diff --git a/src/actions/report.ts b/src/actions/report.ts index f2bd083..9a3a937 100644 --- a/src/actions/report.ts +++ b/src/actions/report.ts @@ -66,8 +66,20 @@ export const report = { const hash = md5Hash.digest('hex'); const filePath = path.join(UPLOAD_PATH!, hash); + let type: 'image' | 'video'; + if (allowedImageTypes.includes(file.type)) { + type = 'image'; + } else if (allowedVideoTypes.includes(file.type)) { + type = 'video'; + } else { + throw new ActionError({ + code: 'BAD_REQUEST', + message: 'Invalid file type' + }); + } + await tx.addReportAttachment({ - type: 'video', + type: type, hash: hash, reportId: report.id }); @@ -198,6 +210,18 @@ export const report = { }; } }), + reportAttachments: defineAction({ + input: z.object({ + reportId: z.number() + }), + handler: async (input, context) => { + Session.actionSessionFromCookies(context.cookies, Permissions.Reports); + + return { + reportAttachments: (await db.getReportAttachments(input)) ?? [] + }; + } + }), addStrikeReason: defineAction({ input: z.object({ name: z.string(), diff --git a/src/app/admin/reports/BottomBar.svelte b/src/app/admin/reports/BottomBar.svelte index 7addc6d..78cdcad 100644 --- a/src/app/admin/reports/BottomBar.svelte +++ b/src/app/admin/reports/BottomBar.svelte @@ -1,5 +1,5 @@