From 98f997387c1e9131a1a0a0e82f312faed148aa4d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 18 Oct 2022 23:50:14 -0400 Subject: [PATCH] fix: Multi-method handlers, regressed in methodOverride removal --- server/routes/api/attachments.ts | 2 +- server/routes/api/cron.ts | 4 +++- server/routes/api/fileOperations.ts | 2 +- server/routes/api/notificationSettings.ts | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/routes/api/attachments.ts b/server/routes/api/attachments.ts index e66e95386..4c92ea15b 100644 --- a/server/routes/api/attachments.ts +++ b/server/routes/api/attachments.ts @@ -147,7 +147,7 @@ router.post("attachments.delete", auth(), async (ctx) => { }); const handleAttachmentsRedirect = async (ctx: ContextWithState) => { - const { id } = (ctx.request.body ?? ctx.request.query) as { id?: string }; + const id = ctx.request.body?.id ?? ctx.request.query?.id; assertUuid(id, "id is required"); const { user } = ctx.state; diff --git a/server/routes/api/cron.ts b/server/routes/api/cron.ts index c8b7da4ed..065c61f0e 100644 --- a/server/routes/api/cron.ts +++ b/server/routes/api/cron.ts @@ -12,7 +12,9 @@ import InviteReminderTask from "@server/queues/tasks/InviteReminderTask"; const router = new Router(); const cronHandler = async (ctx: Context) => { - const { token, limit = 500 } = (ctx.request.body ?? ctx.request.query) as { + const { token, limit = 500 } = (ctx.method === "POST" + ? ctx.request.body + : ctx.request.query) as { token?: string; limit: number; }; diff --git a/server/routes/api/fileOperations.ts b/server/routes/api/fileOperations.ts index a956e69d4..5d0ca697c 100644 --- a/server/routes/api/fileOperations.ts +++ b/server/routes/api/fileOperations.ts @@ -70,7 +70,7 @@ router.post( ); const handleFileOperationsRedirect = async (ctx: ContextWithState) => { - const { id } = (ctx.request.body ?? ctx.request.query) as { id?: string }; + const id = ctx.request.body?.id ?? ctx.request.query?.id; assertUuid(id, "id is required"); const { user } = ctx.state; diff --git a/server/routes/api/notificationSettings.ts b/server/routes/api/notificationSettings.ts index 9f27dc077..5b0c5726f 100644 --- a/server/routes/api/notificationSettings.ts +++ b/server/routes/api/notificationSettings.ts @@ -57,7 +57,9 @@ router.post("notificationSettings.delete", auth(), async (ctx) => { }); const handleUnsubscribe = async (ctx: ContextWithState) => { - const { id, token } = (ctx.request.body ?? ctx.request.query) as { + const { id, token } = (ctx.method === "POST" + ? ctx.request.body + : ctx.request.query) as { id?: string; token?: string; };