ITHC - restrict filetype uploads via api
This commit is contained in:
@@ -6,40 +6,64 @@ import {
|
|||||||
|
|
||||||
import nextConnect from "next-connect";
|
import nextConnect from "next-connect";
|
||||||
import middleware from "../middleware/middleware";
|
import middleware from "../middleware/middleware";
|
||||||
|
import { consoleLogger } from "../../../actions";
|
||||||
|
|
||||||
const ApiProxy = nextConnect();
|
const ApiProxy = nextConnect();
|
||||||
ApiProxy.use(middleware);
|
ApiProxy.use(middleware);
|
||||||
|
|
||||||
ApiProxy.post(async (req, res) => {
|
ApiProxy.post(async (req, res) => {
|
||||||
var checkHash = req.query.hash;
|
var checkHash = req.query.hash;
|
||||||
console.log(JSON.stringify(req.body));
|
// console.log(JSON.stringify(req.body));
|
||||||
console.log(JSON.stringify(req.body.appealData));
|
// console.log(JSON.stringify(req.body.appealData));
|
||||||
console.log(req.files);
|
// console.log(req.files);
|
||||||
|
|
||||||
const containerID = req.body.containerID[0];
|
const containerID = req.body.containerID[0];
|
||||||
const casefolderID = req.body.casefolderID[0];
|
const casefolderID = req.body.casefolderID[0];
|
||||||
|
|
||||||
console.log("there are files:", Object.keys(req.files).length);
|
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);
|
var allowedFilesFormData = {};
|
||||||
//console.log(hashAPIPath(checkquerypath) == "?hash=" + checkHash);
|
|
||||||
|
|
||||||
// if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) {
|
for (const [fileName, fileDetails] of Object.entries(req.files)) {
|
||||||
//createContainer(containerID).then((containerName) => {
|
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 });
|
return res.status(200).json({ data });
|
||||||
});
|
} catch (error) {
|
||||||
|
consoleLogger(error);
|
||||||
//});
|
return res.status(500).json({ error: "Failed to upload files" });
|
||||||
|
}
|
||||||
// } else {
|
|
||||||
// return res.status(400).json();
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
|
|||||||
Reference in New Issue
Block a user