Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix file key search issue
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 756f82f commit a14c072
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions functions/api/infractions/new.ts
Expand Up @@ -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");

Expand Down

0 comments on commit a14c072

Please sign in to comment.