From b124b6c63148d0394b6ef9b9f10a8fb36c010e3b Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:49:12 -0400 Subject: [PATCH] Create per-id appeal middleware --- functions/api/appeals/[id]/_middleware.ts | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 functions/api/appeals/[id]/_middleware.ts diff --git a/functions/api/appeals/[id]/_middleware.ts b/functions/api/appeals/[id]/_middleware.ts new file mode 100644 index 0000000..98a6df2 --- /dev/null +++ b/functions/api/appeals/[id]/_middleware.ts @@ -0,0 +1,32 @@ +export async function onRequestPost(context: RequestContext) { + const { permissions } = context.data.current_user; + + if (!(permissions & (1 << 0)) || !(permissions & (1 << 11))) + return new Response('{"error":"Forbidden"}', { + headers: { + "content-type": "application/json", + }, + status: 403, + }); + + const { body } = context.data; + + if (typeof body.accept !== "boolean") + return new Response('{"error":"Invalid acceptance status"}', { + headers: { + "content-type": "application/json", + }, + status: 400, + }); + + if ( + body.feedback && + (typeof body.feedback !== "string" || body.feedback.length > 512) + ) + return new Response('{"error":"Invalid feedback"}', { + headers: { + "content-type": "application/json", + }, + status: 400, + }); +}