about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/link-meta/resolve-short-link.ts10
-rw-r--r--src/lib/routes/types.ts2
-rw-r--r--src/lib/strings/url-helpers.ts17
3 files changed, 24 insertions, 5 deletions
diff --git a/src/lib/link-meta/resolve-short-link.ts b/src/lib/link-meta/resolve-short-link.ts
index 3a3e2ab46..67d8a5860 100644
--- a/src/lib/link-meta/resolve-short-link.ts
+++ b/src/lib/link-meta/resolve-short-link.ts
@@ -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)
   }
diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts
index 8a173b675..9d102f248 100644
--- a/src/lib/routes/types.ts
+++ b/src/lib/routes/types.ts
@@ -44,6 +44,7 @@ export type CommonNavigatorParams = {
   Feeds: undefined
   Start: {name: string; rkey: string}
   StarterPack: {name: string; rkey: string; new?: boolean}
+  StarterPackShort: {code: string}
   StarterPackWizard: undefined
   StarterPackEdit: {
     rkey?: string
@@ -101,6 +102,7 @@ export type AllNavigatorParams = CommonNavigatorParams & {
   Messages: {animation?: 'push' | 'pop'}
   Start: {name: string; rkey: string}
   StarterPack: {name: string; rkey: string; new?: boolean}
+  StarterPackShort: {code: string}
   StarterPackWizard: undefined
   StarterPackEdit: {
     rkey?: string
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts
index b88b77f73..948279fce 100644
--- a/src/lib/strings/url-helpers.ts
+++ b/src/lib/strings/url-helpers.ts
@@ -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
   }
 }