Fix file uploading for infractions

This commit is contained in:
2023-10-19 16:50:25 -04:00
parent eda287cf86
commit f5b76b69d4

View File

@ -77,6 +77,12 @@ export async function onRequestPost(context: RequestContext) {
// @ts-expect-error // @ts-expect-error
const files: File[] = body.keys().find((key) => key.match(/^files\[\d]$/)); const files: File[] = body.keys().find((key) => key.match(/^files\[\d]$/));
const urlPromises = []; const urlPromises = [];
const origin = context.request.headers.get("Origin");
if (!origin)
return new Response('{"error":"Origin header missing"}', {
status: 400,
});
for (const file of files) { for (const file of files) {
if (!allowedFileTypes.includes(file.type)) if (!allowedFileTypes.includes(file.type))
@ -97,6 +103,7 @@ export async function onRequestPost(context: RequestContext) {
attachmentKey, attachmentKey,
file.size, file.size,
(allowedFileTypes.find((t) => t === file.type) as string).split("/")[1], (allowedFileTypes.find((t) => t === file.type) as string).split("/")[1],
origin,
), ),
); );
} }