Apply labelers and handle language for PWI home (#5816)

This commit is contained in:
Eric Bailey
2024-10-17 15:28:52 -05:00
committed by GitHub
parent e9be8f4574
commit 05ca979518
2 changed files with 30 additions and 4 deletions
+20 -4
View File
@@ -5,7 +5,10 @@ import {
jsonStringToLex,
} from '@atproto/api'
import {getContentLanguages} from '#/state/preferences/languages'
import {
getAppLanguageAsContentLanguage,
getContentLanguages,
} from '#/state/preferences/languages'
import {FeedAPI, FeedAPIResponse} from './types'
import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils'
@@ -103,14 +106,27 @@ async function loggedOutFetch({
limit: number
cursor?: string
}) {
let contentLangs = getContentLanguages().join(',')
let contentLangs = getAppLanguageAsContentLanguage()
/**
* Copied from our root `Agent` class
* @see https://github.com/bluesky-social/atproto/blob/60df3fc652b00cdff71dd9235d98a7a4bb828f05/packages/api/src/agent.ts#L120
*/
const labelersHeader = {
'atproto-accept-labelers': BskyAgent.appLabelers
.map(l => `${l};redact`)
.join(', '),
}
// 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}${
cursor ? `&cursor=${cursor}` : ''
}&limit=${limit}&lang=${contentLangs}`,
{method: 'GET', headers: {'Accept-Language': contentLangs}},
{
method: 'GET',
headers: {'Accept-Language': contentLangs, ...labelersHeader},
},
)
let data = res.ok ? jsonStringToLex(await res.text()) : null
if (data?.feed?.length) {
@@ -125,7 +141,7 @@ async function loggedOutFetch({
`https://api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=${feed}${
cursor ? `&cursor=${cursor}` : ''
}&limit=${limit}`,
{method: 'GET', headers: {'Accept-Language': ''}},
{method: 'GET', headers: {'Accept-Language': '', ...labelersHeader}},
)
data = res.ok ? jsonStringToLex(await res.text()) : null
if (data?.feed?.length) {