Merge branch 'dev' into staging
This commit is contained in:
commit
6783ec98b4
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user