Skip to content

Commit fbc7e75

Browse files
authored
Appview: maintain language info when going out to a suggestions service (bluesky-social#2424)
appview: maintain language info when going out to a suggestions service
1 parent 2002b56 commit fbc7e75

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

packages/bsky/src/api/app/bsky/actor/getSuggestions.ts

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mapDefined } from '@atproto/common'
1+
import { mapDefined, noUndefinedVals } from '@atproto/common'
22
import AppContext from '../../../../context'
33
import { Server } from '../../../../lexicon'
44
import { QueryParams } from '../../../../lexicon/types/app/bsky/actor/getSuggestions'
@@ -27,12 +27,23 @@ export default function (server: Server, ctx: AppContext) {
2727
const viewer = auth.credentials.iss
2828
const labelers = ctx.reqLabelers(req)
2929
const hydrateCtx = await ctx.hydrator.createContext({ viewer, labelers })
30-
const result = await getSuggestions({ ...params, hydrateCtx }, ctx)
31-
30+
const headers = noUndefinedVals({
31+
'accept-language': req.headers['accept-language'],
32+
})
33+
const { resHeaders: resultHeaders, ...result } = await getSuggestions(
34+
{ ...params, hydrateCtx, headers },
35+
ctx,
36+
)
37+
const suggestionsResHeaders = noUndefinedVals({
38+
'content-language': resultHeaders?.['content-language'],
39+
})
3240
return {
3341
encoding: 'application/json',
3442
body: result,
35-
headers: resHeaders({ labelers: hydrateCtx.labelers }),
43+
headers: {
44+
...suggestionsResHeaders,
45+
...resHeaders({ labelers: hydrateCtx.labelers }),
46+
},
3647
}
3748
},
3849
})
@@ -46,14 +57,18 @@ const skeleton = async (input: {
4657
const viewer = params.hydrateCtx.viewer
4758
if (ctx.suggestionsAgent) {
4859
const res =
49-
await ctx.suggestionsAgent.api.app.bsky.unspecced.getSuggestionsSkeleton({
50-
viewer: viewer ?? undefined,
51-
limit: params.limit,
52-
cursor: params.cursor,
53-
})
60+
await ctx.suggestionsAgent.api.app.bsky.unspecced.getSuggestionsSkeleton(
61+
{
62+
viewer: viewer ?? undefined,
63+
limit: params.limit,
64+
cursor: params.cursor,
65+
},
66+
{ headers: params.headers },
67+
)
5468
return {
5569
dids: res.data.actors.map((a) => a.did),
5670
cursor: res.data.cursor,
71+
resHeaders: res.headers,
5772
}
5873
} else {
5974
// @NOTE for appview swap moving to rkey-based cursors which are somewhat permissive, should not hard-break pagination
@@ -111,6 +126,7 @@ const presentation = (input: {
111126
return {
112127
actors,
113128
cursor: skeleton.cursor,
129+
resHeaders: skeleton.resHeaders,
114130
}
115131
}
116132

@@ -123,6 +139,11 @@ type Context = {
123139

124140
type Params = QueryParams & {
125141
hydrateCtx: HydrateCtx
142+
headers: Record<string, string>
126143
}
127144

128-
type Skeleton = { dids: string[]; cursor?: string }
145+
type Skeleton = {
146+
dids: string[]
147+
cursor?: string
148+
resHeaders?: Record<string, string>
149+
}

0 commit comments

Comments
 (0)