Handle pressing all go.bsky.app links in-app w/ resolution (#4680)

This commit is contained in:
Hailey
2024-06-27 19:35:20 -07:00
committed by GitHub
parent 030c8e268e
commit 91c4aa7c2d
9 changed files with 186 additions and 17 deletions
+7 -3
View File
@@ -1,5 +1,4 @@
import {logger} from '#/logger'
import {startUriToStarterPackUri} from 'lib/strings/starter-pack'
export async function resolveShortLink(shortLink: string) {
const controller = new AbortController()
@@ -8,15 +7,20 @@ export async function resolveShortLink(shortLink: string) {
try {
const res = await fetch(shortLink, {
method: 'GET',
headers: {
Accept: 'application/json',
},
signal: controller.signal,
})
if (res.status !== 200) {
logger.error('Failed to resolve short link', {status: res.status})
return shortLink
}
return startUriToStarterPackUri(res.url)
const json = (await res.json()) as {url: string}
return json.url
} catch (e: unknown) {
logger.error('Failed to resolve short link', {safeMessage: e})
return null
return shortLink
} finally {
clearTimeout(to)
}