From 9a6e44b2d507c5125d6bca6a696479f3f571efd1 Mon Sep 17 00:00:00 2001 From: bytedream Date: Sun, 22 Jun 2025 16:29:48 +0200 Subject: [PATCH] show report attachments in admin ui --- src/actions/report.ts | 26 +++++++- src/app/admin/reports/BottomBar.svelte | 66 +++++++++++++++++-- src/app/admin/reports/reports.ts | 12 ++++ src/app/website/report/Dropzone.svelte | 2 - src/db/database.ts | 9 ++- src/db/schema/reportAttachment.ts | 1 - .../admin/reports/attachment/[fileHash].ts | 27 ++++++++ .../{reports.astro => reports/index.astro} | 0 8 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 src/pages/admin/reports/attachment/[fileHash].ts rename src/pages/admin/{reports.astro => reports/index.astro} (100%) 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 @@