From c2ae50e15613148d63d6e9f48a10a5fc00b118e4 Mon Sep 17 00:00:00 2001 From: Vins Date: Mon, 9 Dec 2024 10:44:34 +0100 Subject: [PATCH] New file format --- src/app/middlewares/CustomerHandler/FileHandler.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/middlewares/CustomerHandler/FileHandler.ts b/src/app/middlewares/CustomerHandler/FileHandler.ts index 04bbb277..f308dc8e 100644 --- a/src/app/middlewares/CustomerHandler/FileHandler.ts +++ b/src/app/middlewares/CustomerHandler/FileHandler.ts @@ -19,7 +19,7 @@ export default async function fileHandler(req: Request, response: Response, next const customerEmail = req.body.user.email; const uid = req.path && req.path.split("/")[5]; const file: string | undefined = req.body["q"]; - const mimetypes = ["application/pdf", "image/png", "image/jpeg", "image/webp", "text/csv", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" , "application/vnd.ms-excel"]; + const mimetypes = ["application/pdf", "image/png", "image/jpeg", "image/webp", "text/csv", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" , "application/vnd.ms-excel", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain"]; /** * @description Check if customer has access to the file @@ -52,14 +52,14 @@ export default async function fileHandler(req: Request, response: Response, next const infos = fileTypeChecker.detectFile(req.file!.buffer); // Check mime type from the request directly for CSV - if (req.file.mimetype === "text/csv" || req.file.mimetype === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || req.file.mimetype === "application/vnd.ms-excel") { + if (req.file.mimetype === "text/csv" || req.file.mimetype === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || req.file.mimetype === "application/vnd.ms-excel" || req.file.mimetype === "application/msword" || req.file.mimetype === "application/vnd.openxmlformats-officedocument.wordprocessingml.document" || req.file.mimetype === "text/plain") { // It's a CSV, so you can skip the file-type-checker check for this type } else if (req.file.mimetype !== infos?.mimeType) { response.status(HttpCodes.BAD_REQUEST).send(`Corrupted file, detected: ${infos?.mimeType}, but extension is ${req.file?.mimetype}`); return; } - if (req.file.mimetype === "text/csv" || req.file.mimetype === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || req.file.mimetype === "application/vnd.ms-excel") { + if (req.file.mimetype === "text/csv" || req.file.mimetype === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || req.file.mimetype === "application/vnd.ms-excel" || req.file.mimetype === "application/msword" || req.file.mimetype === "application/vnd.openxmlformats-officedocument.wordprocessingml.document" || req.file.mimetype === "text/plain") { // It's a CSV, so you can skip the file-type-checker check for this type } else if (!infos?.mimeType || mimetypes.indexOf(infos?.mimeType) === -1) {