From 503a3757019fe4f5aa0ae94c3a8896be41b1dc28 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 4 Mar 2026 18:14:39 +0100 Subject: [PATCH] fix: only log FILE_DOWNLOADED for actual downloads, not preview URLs getDownloadUrl was logging FILE_DOWNLOADED on every call including inline previews and thumbnail loads. Now only logs when forDownload is true (explicit download button click), massively reducing noise. Co-Authored-By: Claude Opus 4.6 --- src/server/routers/file.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/server/routers/file.ts b/src/server/routers/file.ts index 72900c7..762ef73 100644 --- a/src/server/routers/file.ts +++ b/src/server/routers/file.ts @@ -124,16 +124,18 @@ export const fileRouter = router({ }) } - // Log file access - await logAudit({ - prisma: ctx.prisma, - userId: ctx.user.id, - action: 'FILE_DOWNLOADED', - entityType: 'ProjectFile', - detailsJson: { bucket: input.bucket, objectKey: input.objectKey }, - ipAddress: ctx.ip, - userAgent: ctx.userAgent, - }) + // Only log actual downloads, not preview/view URL requests + if (input.forDownload) { + await logAudit({ + prisma: ctx.prisma, + userId: ctx.user.id, + action: 'FILE_DOWNLOADED', + entityType: 'ProjectFile', + detailsJson: { bucket: input.bucket, objectKey: input.objectKey, fileName: input.fileName }, + ipAddress: ctx.ip, + userAgent: ctx.userAgent, + }) + } return { url } }),