From a14c0724e19bcaf704f7acbe59a70c60da1684a2 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:51:00 -0400 Subject: [PATCH] Fix file key search issue --- functions/api/infractions/new.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/functions/api/infractions/new.ts b/functions/api/infractions/new.ts index ada5628..99f4922 100644 --- a/functions/api/infractions/new.ts +++ b/functions/api/infractions/new.ts @@ -51,8 +51,24 @@ export async function onRequestPost(context: RequestContext) { if (!(body.get("user") as string).match(/^\d{17,19}$/)) return jsonError("Invalid user", 400); - // @ts-expect-error - const files: File[] = body.keys().find((key) => key.match(/^files\[\d]$/)); + const fileKeys = Array.from(body.keys()).filter((key) => + key.match(/^file\d$/), + ); + + if (fileKeys.length > 5) + return jsonError("Only up to five files are allowed per infraction", 400); + + const files: File[] = []; + + for (const fileKey of fileKeys) { + const file = body.get(fileKey); + + if (!(file instanceof File)) + return jsonError("File keys can only contain files", 400); + + files.push(file); + } + const urlPromises = []; const origin = context.request.headers.get("Origin");