Skip to content

Commit

Permalink
fix validateFileForUpload for non-media files
Browse files Browse the repository at this point in the history
  • Loading branch information
devland committed Dec 4, 2024
1 parent 773a419 commit 9d2156d
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,24 +665,16 @@ const validateFileForUpload = (uploadFieldType, mimeType, extension) => {
const allowedExtensions = config.files.patterns.allowed.toString()
.replace(/[^a-zA-Z0-9|]/g, '')
.split('|');

mimeType = '*'; // Allow allowedExtensions for all mime types
allowed = { mimeType : allowedExtensions };
allowed = { '*': allowedExtensions }; // Allow allowedExtensions for all mime types
break;

default:
allowed = {};
}

const isExtensionAllowed = (allowed[mimeType] ?? []).includes(extension);

const message = isExtensionAllowed ?
'OK' :
`Invalid ${uploadFieldType} file format.`;

const extensionsToUse = isExtensionAllowed ?
'' :
listExtensions(Object.values(allowed).flat());
const isExtensionAllowed = (allowed[mimeType] ?? allowed['*'] ?? []).includes(extension);
const message = isExtensionAllowed ? 'OK' : `Invalid ${uploadFieldType} file format.`;
const extensionsToUse = isExtensionAllowed ? '' : listExtensions(Object.values(allowed).flat());

return [message, extensionsToUse].filter(Boolean).join(' ');
}
Expand Down

0 comments on commit 9d2156d

Please sign in to comment.