Handle pressing all go.bsky.app links in-app w/ resolution (#4680)
This commit is contained in:
parent
030c8e268e
commit
91c4aa7c2d
9 changed files with 186 additions and 17 deletions
|
@ -167,6 +167,9 @@ export function convertBskyAppUrlIfNeeded(url: string): string {
|
|||
} catch (e) {
|
||||
console.error('Unexpected error in convertBskyAppUrlIfNeeded()', e)
|
||||
}
|
||||
} else if (isShortLink(url)) {
|
||||
// We only want to do this on native, web handles the 301 for us
|
||||
return shortLinkToHref(url)
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
@ -288,11 +291,21 @@ export function createBskyAppAbsoluteUrl(path: string): string {
|
|||
}
|
||||
|
||||
export function isShortLink(url: string): boolean {
|
||||
return url.startsWith('https://go.bsky.app/')
|
||||
}
|
||||
|
||||
export function shortLinkToHref(url: string): string {
|
||||
try {
|
||||
const urlp = new URL(url)
|
||||
return urlp.host === 'go.bsky.app'
|
||||
|
||||
// For now we only support starter packs, but in the future we should add additional paths to this check
|
||||
const parts = urlp.pathname.split('/').filter(Boolean)
|
||||
if (parts.length === 1) {
|
||||
return `/starter-pack-short/${parts[0]}`
|
||||
}
|
||||
return url
|
||||
} catch (e) {
|
||||
logger.error('Failed to parse possible short link', {safeMessage: e})
|
||||
return false
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue