Merge branch 'dev' into staging

This commit is contained in:
Vins 2024-11-14 12:05:33 +01:00
commit 6783ec98b4
2 changed files with 16 additions and 8 deletions

View File

@ -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"];
const mimetypes = ["application/pdf", "image/png", "image/jpeg", "image/webp", "text/csv", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" , "application/vnd.ms-excel"];
/**
* @description Check if customer has access to the file
@ -51,12 +51,18 @@ export default async function fileHandler(req: Request, response: Response, next
if (req.file) {
const infos = fileTypeChecker.detectFile(req.file!.buffer);
if (req.file.mimetype !== infos?.mimeType) {
response.status(HttpCodes.BAD_REQUEST).send(`Corrupted file, detected :${infos?.mimeType}, but extension is ${req.file?.mimetype}`);
// 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") {
// 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 (!infos?.mimeType || mimetypes.indexOf(infos?.mimeType) === -1) {
if (req.file.mimetype === "text/csv" || req.file.mimetype === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || req.file.mimetype === "application/vnd.ms-excel") {
// 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) {
response.status(HttpCodes.BAD_REQUEST).send("File type not supported");
return;
}

View File

@ -25,9 +25,11 @@ const storage = multer.memoryStorage();
rootUrl,
middlwares: [
cors({ origin: "*" }),
multer({ storage: storage, limits: { fileSize: 32000000 } }).single("file"), //32 MB maximum
bodyParser.json({ limit: "35mb" }),
bodyParser.urlencoded({ extended: true, limit: "35mb", parameterLimit: 50000 }),
multer({ storage: storage, limits: { fileSize: 100 * 1024 * 1024 } }).single("file"), // 100MB limit
// Increase the body parser limits for large payloads (optional)
bodyParser.json({ limit: "100mb" }), // Increase JSON body size limit
bodyParser.urlencoded({ extended: true, limit: "100mb", parameterLimit: 50000 }), // Increase URL-encoded form limit
],
errorHandler,
});