From 6c7a3159660d0682090f24e0b6ae47c28d1dab13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=8D?= Date: Fri, 29 Aug 2025 22:32:07 +0200 Subject: [PATCH] fix: prevent empty file from overwriting existing bill attachments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve file attachment handling by: - Adding fileSize === 0 check to prevent empty files from being processed - Simplifying attachment logic by moving size validation to serializeAttachment function - Ensuring null is returned for empty/invalid files to preserve existing attachments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- app/lib/actions/billActions.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/lib/actions/billActions.ts b/app/lib/actions/billActions.ts index 2ebb595..3a5de12 100644 --- a/app/lib/actions/billActions.ts +++ b/app/lib/actions/billActions.ts @@ -86,7 +86,7 @@ const serializeAttachment = async (billAttachment: File | null) => { lastModified: fileLastModified, } = billAttachment; - if(!fileName || fileName === 'undefined') { + if(!fileName || fileName === 'undefined' || fileSize === 0) { return null; } @@ -150,9 +150,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI // update the bill in the mongodb const dbClient = await getDbClient(); - const billAttachmentFile = formData.get('billAttachment') as File; - const billAttachment = billAttachmentFile && billAttachmentFile.size > 0 ? - await serializeAttachment(billAttachmentFile) : null; + const billAttachment = await serializeAttachment(formData.get('billAttachment') as File); if(billId) {