Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@clarksandholtz/no strip snack prefix #3

Open
wants to merge 3 commits into
base: @bycedric/snack-runtime
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions runtime/src/utils/SnackUrlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export function extractChannelFromSnackUrl(url: string): string | null {
return matches ? matches[2] : null;
}

const snackPrefix = '@snack/';
const snackDomains = [
'http://snack.expo.dev/',
'https://snack.expo.dev/',
Expand All @@ -30,6 +29,9 @@ const snackDomains = [

export function extractSnackIdentifierFromSnackUrl(urlString: string): string | null {
try {
if (isEphemeralSnackUrl(urlString)) {
return null;
}
const snackDomain = snackDomains.find(domain => urlString.startsWith(domain));
if (!snackDomain) {
return null;
Expand All @@ -41,15 +43,22 @@ export function extractSnackIdentifierFromSnackUrl(urlString: string): string |
if (identifier.includes('+')) { // check for a channel id
identifier = identifier.split('+')[0]
}
if (identifier.startsWith(snackPrefix)) {
identifier = identifier.slice(snackPrefix.length)
}
return identifier;
} catch {
return null;
}
}

export function createSnackUrlFromHashId(hashId: string): string {
return `https://exp.host/@snack/${hashId}`;
export function createSnackUrlFromSnackIdentifier(snackIdentifier: string): string {
return snackIdentifier.startsWith('@')
? `https://exp.host/${snackIdentifier}`
: `https://exp.host/@snack/${snackIdentifier}`
}

export function isEphemeralSnackUrl(snackUrl: string): boolean {
if (snackUrl == null) {
return false
}
const matches = snackUrl.match(channelRegex)
return matches != null && matches[1].length > 1
}