Merge branch 'staging' into preprod

This commit is contained in:
Vins 2024-12-09 10:44:53 +01:00
commit 23b5300c94

View File

@ -19,7 +19,7 @@ export default async function fileHandler(req: Request, response: Response, next
const customerEmail = req.body.user.email; const customerEmail = req.body.user.email;
const uid = req.path && req.path.split("/")[5]; const uid = req.path && req.path.split("/")[5];
const file: string | undefined = req.body["q"]; 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 * @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); const infos = fileTypeChecker.detectFile(req.file!.buffer);
// Check mime type from the request directly for CSV // 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 // It's a CSV, so you can skip the file-type-checker check for this type
} else if (req.file.mimetype !== infos?.mimeType) { } else if (req.file.mimetype !== infos?.mimeType) {
response.status(HttpCodes.BAD_REQUEST).send(`Corrupted file, detected: ${infos?.mimeType}, but extension is ${req.file?.mimetype}`); response.status(HttpCodes.BAD_REQUEST).send(`Corrupted file, detected: ${infos?.mimeType}, but extension is ${req.file?.mimetype}`);
return; 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 // 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) { } else if (!infos?.mimeType || mimetypes.indexOf(infos?.mimeType) === -1) {