Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix RSS URLs treated as internal (#3156)

* Fix RSS URLs treated as internal

* Add utils to patch relative RSS external links

* modify router to support multiple paths

---------

Co-authored-by: Hailey <me@haileyok.com>

authored by

Eric Bailey
Hailey
and committed by
GitHub
594958c6 aad8c080

+40 -5
+8 -2
src/lib/routes/router.ts
··· 2 2 3 3 export class Router { 4 4 routes: [string, Route][] = [] 5 - constructor(description: Record<string, string>) { 5 + constructor(description: Record<string, string | string[]>) { 6 6 for (const [screen, pattern] of Object.entries(description)) { 7 - this.routes.push([screen, createRoute(pattern)]) 7 + if (typeof pattern === 'string') { 8 + this.routes.push([screen, createRoute(pattern)]) 9 + } else { 10 + pattern.forEach(subPattern => { 11 + this.routes.push([screen, createRoute(subPattern)]) 12 + }) 13 + } 8 14 } 9 15 } 10 16
+22 -2
src/lib/strings/url-helpers.ts
··· 3 3 import TLDs from 'tlds' 4 4 import psl from 'psl' 5 5 6 + export const BSKY_APP_HOST = 'https://bsky.app' 7 + 6 8 export function isValidDomain(str: string): boolean { 7 9 return !!TLDs.find(tld => { 8 10 let i = str.lastIndexOf(tld) ··· 67 69 return url.startsWith('https://bsky.app/') 68 70 } 69 71 72 + export function isRelativeUrl(url: string): boolean { 73 + return /^\/[^/]/.test(url) 74 + } 75 + 76 + export function isBskyRSSUrl(url: string): boolean { 77 + return ( 78 + (url.startsWith('https://bsky.app/') || isRelativeUrl(url)) && 79 + /\/rss\/?$/.test(url) 80 + ) 81 + } 82 + 70 83 export function isExternalUrl(url: string): boolean { 71 - return !isBskyAppUrl(url) && url.startsWith('http') 84 + const external = !isBskyAppUrl(url) && url.startsWith('http') 85 + const rss = isBskyRSSUrl(url) 86 + return external || rss 72 87 } 73 88 74 89 export function isBskyPostUrl(url: string): boolean { ··· 149 164 const labelDomain = labelToDomain(label) 150 165 151 166 // If the uri started with a / we know it is internal. 152 - if (uri.startsWith('/')) { 167 + if (isRelativeUrl(uri)) { 153 168 return false 154 169 } 155 170 ··· 222 237 hostnamep.domain, 223 238 ] 224 239 } 240 + 241 + export function createBskyAppAbsoluteUrl(path: string): string { 242 + const sanitizedPath = path.replace(BSKY_APP_HOST, '').replace(/^\/+/, '') 243 + return `${BSKY_APP_HOST.replace(/\/$/, '')}/${sanitizedPath}` 244 + }
+1 -1
src/routes.ts
··· 12 12 ModerationModlists: '/moderation/modlists', 13 13 ModerationMutedAccounts: '/moderation/muted-accounts', 14 14 ModerationBlockedAccounts: '/moderation/blocked-accounts', 15 - Profile: '/profile/:name', 15 + Profile: ['/profile/:name', '/profile/:name/rss'], 16 16 ProfileFollowers: '/profile/:name/followers', 17 17 ProfileFollows: '/profile/:name/follows', 18 18 ProfileList: '/profile/:name/lists/:rkey',
+9
src/state/preferences/in-app-browser.tsx
··· 5 5 import {isNative} from '#/platform/detection' 6 6 import {useModalControls} from '../modals' 7 7 import {usePalette} from 'lib/hooks/usePalette' 8 + import { 9 + isBskyRSSUrl, 10 + isRelativeUrl, 11 + createBskyAppAbsoluteUrl, 12 + } from 'lib/strings/url-helpers' 8 13 9 14 type StateContext = persisted.Schema['useInAppBrowser'] 10 15 type SetContext = (v: persisted.Schema['useInAppBrowser']) => void ··· 57 62 58 63 const openLink = React.useCallback( 59 64 (url: string, override?: boolean) => { 65 + if (isBskyRSSUrl(url) && isRelativeUrl(url)) { 66 + url = createBskyAppAbsoluteUrl(url) 67 + } 68 + 60 69 if (isNative && !url.startsWith('mailto:')) { 61 70 if (override === undefined && enabled === undefined) { 62 71 openModal({