From 5630a12c1f074546783a60808e2f672279809034 Mon Sep 17 00:00:00 2001 From: dholms Date: Tue, 14 Nov 2023 22:20:12 -0600 Subject: [PATCH] correctly proxy feed.searchPosts --- .../pds/src/api/app/bsky/feed/searchPosts.ts | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/pds/src/api/app/bsky/feed/searchPosts.ts b/packages/pds/src/api/app/bsky/feed/searchPosts.ts index 85384751ea1..28811ee8334 100644 --- a/packages/pds/src/api/app/bsky/feed/searchPosts.ts +++ b/packages/pds/src/api/app/bsky/feed/searchPosts.ts @@ -1,14 +1,37 @@ import { Server } from '../../../../lexicon' import AppContext from '../../../../context' +import { + authPassthru, + proxy, + proxyAppView, + resultPassthru, +} from '../../../proxy' export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.searchPosts({ auth: ctx.authVerifier.access, - handler: async ({ params, auth }) => { + handler: async ({ params, auth, req }) => { + const proxied = await proxy( + ctx, + auth.credentials.audience, + async (agent) => { + const result = await agent.api.app.bsky.feed.searchPosts( + params, + authPassthru(req), + ) + return resultPassthru(result) + }, + ) + if (proxied !== null) { + return proxied + } + const requester = auth.credentials.did - const res = await ctx.appViewAgent.api.app.bsky.feed.searchPosts( - params, - await ctx.serviceAuthHeaders(requester), + const res = await proxyAppView(ctx, async (agent) => + agent.api.app.bsky.feed.searchPosts( + params, + await ctx.serviceAuthHeaders(requester), + ), ) return { encoding: 'application/json',