about summary refs log tree commit diff
path: root/src/lib/strings/url-helpers.ts
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-06-27 19:35:20 -0700
committerGitHub <noreply@github.com>2024-06-27 19:35:20 -0700
commit91c4aa7c2dc598dd5e2c828e44c0d2c94cf0967d (patch)
tree362f79f88bab8107053c1fe0201ddcb4d0d21ac5 /src/lib/strings/url-helpers.ts
parent030c8e268e161bebe360e3ad97b1c18bd8425ca8 (diff)
downloadvoidsky-91c4aa7c2dc598dd5e2c828e44c0d2c94cf0967d.tar.zst
Handle pressing all go.bsky.app links in-app w/ resolution (#4680)
Diffstat (limited to 'src/lib/strings/url-helpers.ts')
-rw-r--r--src/lib/strings/url-helpers.ts17
1 files changed, 15 insertions, 2 deletions
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
   }
 }