72 lines
2.7 KiB
Diff
72 lines
2.7 KiB
Diff
diff --git a/src/lib/api/feed/custom.ts b/src/lib/api/feed/custom.ts
|
|
index 18bb8c8f0..bab286d7a 100644
|
|
--- a/src/lib/api/feed/custom.ts
|
|
+++ b/src/lib/api/feed/custom.ts
|
|
@@ -5,6 +5,7 @@ import {
|
|
jsonStringToLex,
|
|
} from '@atproto/api'
|
|
|
|
+import {PUBLIC_APPVIEW} from '#/lib/constants'
|
|
import {
|
|
getAppLanguageAsContentLanguage,
|
|
getContentLanguages,
|
|
@@ -12,6 +13,17 @@ import {
|
|
import {type FeedAPI, type FeedAPIResponse} from './types'
|
|
import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils'
|
|
|
|
+// Check if the feed is hosted on syu.is network
|
|
+function isSyuIsFeed(feedUri: string): boolean {
|
|
+ return feedUri.includes('did:plc:6qyecktefllvenje24fcxnie') || feedUri.includes('syu.is')
|
|
+}
|
|
+
|
|
+// Check if the agent is connected to syu.is
|
|
+function isAgentOnSyuIs(agent: BskyAgent): boolean {
|
|
+ const serviceUrl = agent.service?.toString() || ''
|
|
+ return serviceUrl.includes('syu.is')
|
|
+}
|
|
+
|
|
export class CustomFeedAPI implements FeedAPI {
|
|
agent: BskyAgent
|
|
params: GetCustomFeed.QueryParams
|
|
@@ -54,8 +66,12 @@ export class CustomFeedAPI implements FeedAPI {
|
|
const agent = this.agent
|
|
const isBlueskyOwned = isBlueskyOwnedFeed(this.params.feed)
|
|
|
|
- const res = agent.did
|
|
- ? await this.agent.app.bsky.feed.getFeed(
|
|
+ // For syu.is feeds accessed from non-syu.is accounts, use PUBLIC_APPVIEW
|
|
+ const needsPublicAppView = isSyuIsFeed(this.params.feed) && !isAgentOnSyuIs(agent)
|
|
+
|
|
+ const res = !agent.did || needsPublicAppView
|
|
+ ? await loggedOutFetch({...this.params, cursor, limit})
|
|
+ : await this.agent.app.bsky.feed.getFeed(
|
|
{
|
|
...this.params,
|
|
cursor,
|
|
@@ -70,7 +86,6 @@ export class CustomFeedAPI implements FeedAPI {
|
|
},
|
|
},
|
|
)
|
|
- : await loggedOutFetch({...this.params, cursor, limit})
|
|
if (res.success) {
|
|
// NOTE
|
|
// some custom feeds fail to enforce the pagination limit
|
|
@@ -120,7 +135,7 @@ async function loggedOutFetch({
|
|
|
|
// manually construct fetch call so we can add the `lang` cache-busting param
|
|
let res = await fetch(
|
|
- `https://api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=${feed}${
|
|
+ `${PUBLIC_APPVIEW}/xrpc/app.bsky.feed.getFeed?feed=${encodeURIComponent(feed)}${
|
|
cursor ? `&cursor=${cursor}` : ''
|
|
}&limit=${limit}&lang=${contentLangs}`,
|
|
{
|
|
@@ -140,7 +155,7 @@ async function loggedOutFetch({
|
|
|
|
// no data, try again with language headers removed
|
|
res = await fetch(
|
|
- `https://api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=${feed}${
|
|
+ `${PUBLIC_APPVIEW}/xrpc/app.bsky.feed.getFeed?feed=${encodeURIComponent(feed)}${
|
|
cursor ? `&cursor=${cursor}` : ''
|
|
}&limit=${limit}`,
|
|
{method: 'GET', headers: {'Accept-Language': '', ...labelersHeader}},
|