Merge branch 'staging' into preprod
This commit is contained in:
commit
f1f9871a51
@ -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"];
|
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
|
* @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) {
|
if (req.file) {
|
||||||
const infos = fileTypeChecker.detectFile(req.file!.buffer);
|
const infos = fileTypeChecker.detectFile(req.file!.buffer);
|
||||||
|
|
||||||
if (req.file.mimetype !== infos?.mimeType) {
|
// Check mime type from the request directly for CSV
|
||||||
response.status(HttpCodes.BAD_REQUEST).send(`Corrupted file, detected :${infos?.mimeType}, but extension is ${req.file?.mimetype}`);
|
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;
|
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");
|
response.status(HttpCodes.BAD_REQUEST).send("File type not supported");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,11 @@ const storage = multer.memoryStorage();
|
|||||||
rootUrl,
|
rootUrl,
|
||||||
middlwares: [
|
middlwares: [
|
||||||
cors({ origin: "*" }),
|
cors({ origin: "*" }),
|
||||||
multer({ storage: storage, limits: { fileSize: 32000000 } }).single("file"), //32 MB maximum
|
multer({ storage: storage, limits: { fileSize: 100 * 1024 * 1024 } }).single("file"), // 100MB limit
|
||||||
bodyParser.json({ limit: "35mb" }),
|
|
||||||
bodyParser.urlencoded({ extended: true, limit: "35mb", parameterLimit: 50000 }),
|
// 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,
|
errorHandler,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user