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/hooks/useOpenLink.ts7
-rw-r--r--src/lib/strings/url-helpers.ts15
2 files changed, 21 insertions, 1 deletions
diff --git a/src/lib/hooks/useOpenLink.ts b/src/lib/hooks/useOpenLink.ts
index 0629656ac..a949dacc6 100644
--- a/src/lib/hooks/useOpenLink.ts
+++ b/src/lib/hooks/useOpenLink.ts
@@ -5,6 +5,7 @@ import * as WebBrowser from 'expo-web-browser'
 import {logEvent} from '#/lib/statsig/statsig'
 import {
   createBskyAppAbsoluteUrl,
+  createProxiedUrl,
   isBskyAppUrl,
   isBskyRSSUrl,
   isRelativeUrl,
@@ -23,7 +24,7 @@ export function useOpenLink() {
   const sheetWrapper = useSheetWrapper()
 
   const openLink = useCallback(
-    async (url: string, override?: boolean) => {
+    async (url: string, override?: boolean, shouldProxy?: boolean) => {
       if (isBskyRSSUrl(url) && isRelativeUrl(url)) {
         url = createBskyAppAbsoluteUrl(url)
       }
@@ -33,6 +34,10 @@ export function useOpenLink() {
           domain: toNiceDomain(url),
           url,
         })
+
+        if (shouldProxy) {
+          url = createProxiedUrl(url)
+        }
       }
 
       if (isNative && !url.startsWith('mailto:')) {
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts
index c44fdf7c2..bb533b12e 100644
--- a/src/lib/strings/url-helpers.ts
+++ b/src/lib/strings/url-helpers.ts
@@ -320,6 +320,21 @@ export function createBskyAppAbsoluteUrl(path: string): string {
   return `${BSKY_APP_HOST.replace(/\/$/, '')}/${sanitizedPath}`
 }
 
+export function createProxiedUrl(url: string): string {
+  let u
+  try {
+    u = URL.parse(url)
+  } catch {
+    return url
+  }
+
+  if (u?.protocol !== 'http:' && u?.protocol !== 'https:') {
+    return url
+  }
+
+  return `https://go.bsky.app/redirect?u=${url}`
+}
+
 export function isShortLink(url: string): boolean {
   return url.startsWith('https://go.bsky.app/')
 }