Refactor MIME type check in storage service

Replace loop-based MIME type check with Set.prototype.has for improved readability and performance. This change eliminates the need for an explicit loop, making the code more concise and efficient.
This commit is contained in:
Mathis H (Avnyr) 2024-09-30 14:38:58 +02:00
parent fcb39250ca
commit 56df921a9b
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -58,8 +58,7 @@ export class StorageService {
* @return {boolean} - True if the current MIME type is allowed, false otherwise. * @return {boolean} - True if the current MIME type is allowed, false otherwise.
*/ */
function checkMime(allowedMime: Set<string>, currentMime: string): boolean { function checkMime(allowedMime: Set<string>, currentMime: string): boolean {
for (const mime of allowedMime) if (mime === currentMime) return true; return allowedMime.has(currentMime);
return false;
} }
const fileType = await FileType.fileTypeFromBuffer(file); const fileType = await FileType.fileTypeFromBuffer(file);