fix: prevent empty file from overwriting existing bill attachments
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 <noreply@anthropic.com>
This commit is contained in:
@@ -86,7 +86,7 @@ const serializeAttachment = async (billAttachment: File | null) => {
|
|||||||
lastModified: fileLastModified,
|
lastModified: fileLastModified,
|
||||||
} = billAttachment;
|
} = billAttachment;
|
||||||
|
|
||||||
if(!fileName || fileName === 'undefined') {
|
if(!fileName || fileName === 'undefined' || fileSize === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,9 +150,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
|||||||
// update the bill in the mongodb
|
// update the bill in the mongodb
|
||||||
const dbClient = await getDbClient();
|
const dbClient = await getDbClient();
|
||||||
|
|
||||||
const billAttachmentFile = formData.get('billAttachment') as File;
|
const billAttachment = await serializeAttachment(formData.get('billAttachment') as File);
|
||||||
const billAttachment = billAttachmentFile && billAttachmentFile.size > 0 ?
|
|
||||||
await serializeAttachment(billAttachmentFile) : null;
|
|
||||||
|
|
||||||
if(billId) {
|
if(billId) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user