Skip to content

Commit

Permalink
Correctly proxy procedures to chat (#2510)
Browse files Browse the repository at this point in the history
* correctly proxy proceudres to chat

* tidy
  • Loading branch information
dholms authored May 23, 2024
1 parent 9fcb78d commit 7450ea3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
32 changes: 16 additions & 16 deletions packages/pds/src/api/chat/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import AppContext from '../../context'
import { Server } from '../../lexicon'
import { pipethrough } from '../../pipethrough'
import { pipethrough, pipethroughProcedure } from '../../pipethrough'

export default function (server: Server, ctx: AppContext) {
server.chat.bsky.actor.deleteAccount({
auth: ctx.authVerifier.accessNotAppPassword,
handler: async ({ req, auth }) => {
return pipethrough(ctx, req, auth.credentials.did)
return pipethroughProcedure(ctx, req, auth.credentials.did)
},
})
server.chat.bsky.actor.exportAccountData({
Expand All @@ -17,8 +17,8 @@ export default function (server: Server, ctx: AppContext) {
})
server.chat.bsky.convo.deleteMessageForSelf({
auth: ctx.authVerifier.accessNotAppPassword,
handler: ({ req, auth }) => {
return pipethrough(ctx, req, auth.credentials.did)
handler: ({ req, auth, input }) => {
return pipethroughProcedure(ctx, req, auth.credentials.did, input.body)
},
})
server.chat.bsky.convo.getConvo({
Expand Down Expand Up @@ -47,8 +47,8 @@ export default function (server: Server, ctx: AppContext) {
})
server.chat.bsky.convo.leaveConvo({
auth: ctx.authVerifier.accessNotAppPassword,
handler: ({ req, auth }) => {
return pipethrough(ctx, req, auth.credentials.did)
handler: ({ req, auth, input }) => {
return pipethroughProcedure(ctx, req, auth.credentials.did, input.body)
},
})
server.chat.bsky.convo.listConvos({
Expand All @@ -59,32 +59,32 @@ export default function (server: Server, ctx: AppContext) {
})
server.chat.bsky.convo.muteConvo({
auth: ctx.authVerifier.accessNotAppPassword,
handler: ({ req, auth }) => {
return pipethrough(ctx, req, auth.credentials.did)
handler: ({ req, auth, input }) => {
return pipethroughProcedure(ctx, req, auth.credentials.did, input.body)
},
})
server.chat.bsky.convo.sendMessage({
auth: ctx.authVerifier.accessNotAppPassword,
handler: ({ req, auth }) => {
return pipethrough(ctx, req, auth.credentials.did)
handler: ({ req, auth, input }) => {
return pipethroughProcedure(ctx, req, auth.credentials.did, input.body)
},
})
server.chat.bsky.convo.sendMessageBatch({
auth: ctx.authVerifier.accessNotAppPassword,
handler: ({ req, auth }) => {
return pipethrough(ctx, req, auth.credentials.did)
handler: ({ req, auth, input }) => {
return pipethroughProcedure(ctx, req, auth.credentials.did, input.body)
},
})
server.chat.bsky.convo.unmuteConvo({
auth: ctx.authVerifier.accessNotAppPassword,
handler: ({ req, auth }) => {
return pipethrough(ctx, req, auth.credentials.did)
handler: ({ req, auth, input }) => {
return pipethroughProcedure(ctx, req, auth.credentials.did, input.body)
},
})
server.chat.bsky.convo.updateRead({
auth: ctx.authVerifier.accessNotAppPassword,
handler: ({ req, auth }) => {
return pipethrough(ctx, req, auth.credentials.did)
handler: ({ req, auth, input }) => {
return pipethroughProcedure(ctx, req, auth.credentials.did, input.body)
},
})
}
18 changes: 17 additions & 1 deletion packages/pds/src/pipethrough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ui8 from 'uint8arrays'
import net from 'node:net'
import stream from 'node:stream'
import webStream from 'node:stream/web'
import { jsonToLex } from '@atproto/lexicon'
import { LexValue, jsonToLex, stringifyLex } from '@atproto/lexicon'
import {
CatchallHandler,
HandlerPipeThrough,
Expand Down Expand Up @@ -45,6 +45,22 @@ export const pipethrough = async (
return parseProxyRes(res)
}

export const pipethroughProcedure = async (
ctx: AppContext,
req: express.Request,
requester: string | null,
body?: LexValue,
): Promise<HandlerPipeThrough> => {
const { url, aud } = await formatUrlAndAud(ctx, req)
const headers = await formatHeaders(ctx, req, aud, requester)
const encodedBody = body
? new TextEncoder().encode(stringifyLex(body))
: undefined
const reqInit = formatReqInit(req, headers, encodedBody)
const res = await makeRequest(url, reqInit)
return parseProxyRes(res)
}

// Request setup/formatting
// -------------------

Expand Down

0 comments on commit 7450ea3

Please sign in to comment.