ITHC - restrict filetype uploads via api
This commit is contained in:
@@ -6,40 +6,64 @@ import {
|
||||
|
||||
import nextConnect from "next-connect";
|
||||
import middleware from "../middleware/middleware";
|
||||
import { consoleLogger } from "../../../actions";
|
||||
|
||||
const ApiProxy = nextConnect();
|
||||
ApiProxy.use(middleware);
|
||||
|
||||
ApiProxy.post(async (req, res) => {
|
||||
var checkHash = req.query.hash;
|
||||
console.log(JSON.stringify(req.body));
|
||||
console.log(JSON.stringify(req.body.appealData));
|
||||
console.log(req.files);
|
||||
// console.log(JSON.stringify(req.body));
|
||||
// console.log(JSON.stringify(req.body.appealData));
|
||||
// console.log(req.files);
|
||||
|
||||
const containerID = req.body.containerID[0];
|
||||
const casefolderID = req.body.casefolderID[0];
|
||||
|
||||
console.log("there are files:", Object.keys(req.files).length);
|
||||
|
||||
// var checkquerypath = "/api/file/upload";
|
||||
// Add other mimetypes here
|
||||
const allowedMimeTypes = [
|
||||
"application/pdf",
|
||||
"application/msword",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"image/tiff",
|
||||
"image/jpeg",
|
||||
"application/zip",
|
||||
"image/png",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
];
|
||||
|
||||
//console.log(hashAPIPath(checkquerypath), checkHash);
|
||||
//console.log(hashAPIPath(checkquerypath) == "?hash=" + checkHash);
|
||||
var allowedFilesFormData = {};
|
||||
|
||||
// if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) {
|
||||
//createContainer(containerID).then((containerName) => {
|
||||
for (const [fileName, fileDetails] of Object.entries(req.files)) {
|
||||
if (allowedMimeTypes.includes(fileDetails[0].headers["content-type"])) {
|
||||
allowedFilesFormData[fileName] = fileDetails.map((file) => ({
|
||||
fieldName: file.fieldName,
|
||||
originalFilename: file.originalFilename,
|
||||
path: file.path,
|
||||
size: file.size,
|
||||
headers: file.headers,
|
||||
contentType: file.headers["content-type"],
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
console.log("does this get folder name:", containerID, casefolderID);
|
||||
//console.log("allowedFilesFormData: ", allowedFilesFormData);
|
||||
|
||||
uploadSingleFile(req.files, containerID, casefolderID).then((data) => {
|
||||
try {
|
||||
const data = await uploadSingleFile(
|
||||
allowedFilesFormData,
|
||||
containerID,
|
||||
casefolderID
|
||||
).then((data) => {
|
||||
return res.status(200).json({ data });
|
||||
});
|
||||
return res.status(200).json({ data });
|
||||
});
|
||||
|
||||
//});
|
||||
|
||||
// } else {
|
||||
// return res.status(400).json();
|
||||
// }
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return res.status(500).json({ error: "Failed to upload files" });
|
||||
}
|
||||
});
|
||||
|
||||
export const config = {
|
||||
|
||||
Reference in New Issue
Block a user