Mirror — see github.com/blacksky-algorithms/blacksky.community
6
fork

Configure Feed

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

Route trending feed requests through Bluesky appview

Add getProxyHeadersForFeed() helper that detects trending feed URIs
and sets atproto-proxy to Bluesky's appview. The Blacksky appview
cannot resolve did:web:topics.bsky.app (Bluesky's trending feed
service), causing 400 errors for trending topic feeds.

Applied to CustomFeedAPI, MergeFeedAPI, and useFeedSourceInfoQuery.

+31 -10
+12 -2
src/lib/api/feed/custom.ts
··· 10 10 getContentLanguages, 11 11 } from '#/state/preferences/languages' 12 12 import {type FeedAPI, type FeedAPIResponse} from './types' 13 - import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils' 13 + import { 14 + createBskyTopicsHeader, 15 + getProxyHeadersForFeed, 16 + isBlueskyOwnedFeed, 17 + } from './utils' 14 18 15 19 export class CustomFeedAPI implements FeedAPI { 16 20 agent: BskyAgent ··· 38 42 ...this.params, 39 43 limit: 1, 40 44 }, 41 - {headers: {'Accept-Language': contentLangs}}, 45 + { 46 + headers: { 47 + ...getProxyHeadersForFeed(this.params.feed), 48 + 'Accept-Language': contentLangs, 49 + }, 50 + }, 42 51 ) 43 52 return res.data.feed[0] 44 53 } ··· 63 72 }, 64 73 { 65 74 headers: { 75 + ...getProxyHeadersForFeed(this.params.feed), 66 76 ...(isBlueskyOwned 67 77 ? createBskyTopicsHeader(this.userInterests) 68 78 : {}),
+6 -1
src/lib/api/feed/merge.ts
··· 17 17 type FeedAPIResponse, 18 18 type ReasonFeedSource, 19 19 } from './types' 20 - import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils' 20 + import { 21 + createBskyTopicsHeader, 22 + getProxyHeadersForFeed, 23 + isBlueskyOwnedFeed, 24 + } from './utils' 21 25 22 26 const REQUEST_WAIT_MS = 500 // 500ms 23 27 const POST_AGE_CUTOFF = 60e3 * 60 * 24 // 24hours ··· 299 303 }, 300 304 { 301 305 headers: { 306 + ...getProxyHeadersForFeed(this.feedUri), 302 307 ...(isBlueskyOwned 303 308 ? createBskyTopicsHeader(this.userInterests) 304 309 : {}),
+11 -1
src/lib/api/feed/utils.ts
··· 2 2 3 3 import {BSKY_FEED_OWNER_DIDS} from '#/lib/constants' 4 4 import {type UsePreferencesQueryResponse} from '#/state/queries/preferences' 5 - import {IS_WEB} from '#/env' 5 + import {ALT_PROXY_DID, IS_WEB} from '#/env' 6 + 7 + const TRENDING_FEED_DID = 'did:plc:qrz3lhbyuxbeilrc6nekdqme' 8 + const PROXY_TO_BLUESKY = `${ALT_PROXY_DID}#bsky_appview` 6 9 7 10 let debugTopics = '' 8 11 if (IS_WEB && typeof window !== 'undefined') { ··· 26 29 const uri = new AtUri(feedUri) 27 30 return BSKY_FEED_OWNER_DIDS.includes(uri.host) 28 31 } 32 + 33 + export function getProxyHeadersForFeed(feedUri: string) { 34 + if (feedUri.includes(TRENDING_FEED_DID)) { 35 + return {'atproto-proxy': PROXY_TO_BLUESKY} 36 + } 37 + return {} 38 + }
+2 -6
src/state/queries/feed.ts
··· 20 20 useQueryClient, 21 21 } from '@tanstack/react-query' 22 22 23 + import {getProxyHeadersForFeed} from '#/lib/api/feed/utils' 23 24 import {DISCOVER_FEED_URI, DISCOVER_SAVED_FEED} from '#/lib/constants' 24 25 import {sanitizeDisplayName} from '#/lib/strings/display-names' 25 26 import {sanitizeHandle} from '#/lib/strings/handles' ··· 27 28 import {RQKEY as listQueryKey} from '#/state/queries/list' 28 29 import {usePreferencesQuery} from '#/state/queries/preferences' 29 30 import {useAgent, useSession} from '#/state/session' 30 - import {ALT_PROXY_DID} from '#/env' 31 31 import {router} from '#/routes' 32 32 import {useModerationOpts} from '../preferences/moderation-opts' 33 33 import {type FeedDescriptor} from './post-feed' ··· 171 171 return getFeedTypeFromUri(uri) === 'feed' ? 'algo' : 'list' 172 172 } 173 173 174 - const PROXY_TO_BLUESKY = `${ALT_PROXY_DID}#bsky_appview` 175 - 176 174 export function useFeedSourceInfoQuery({uri}: {uri: string}) { 177 175 const type = getFeedTypeFromUri(uri) 178 176 const agent = useAgent() 179 177 180 - // Check if this is a trending feed that needs proxying 181 - const needsProxy = uri.includes('did:plc:qrz3lhbyuxbeilrc6nekdqme') 182 - const headers = needsProxy ? {'atproto-proxy': PROXY_TO_BLUESKY} : {} 178 + const headers = getProxyHeadersForFeed(uri) 183 179 184 180 return useQuery({ 185 181 staleTime: STALE.INFINITY,