import { createBlob, createRepBlob, uploadFile } from "../../../actions/azurestorage"; import { hashAPIPath } from "../../../actions/core/hash"; import { respondError, respondSuccess } from "../middleware/apiResponse"; import nextConnect from "next-connect"; import middleware from "../middleware/middleware"; const ApiProxy = nextConnect(); ApiProxy.use(middleware); ApiProxy.post(async (req, res) => { var checkHash = req.query.hash; if (typeof checkHash === "undefined" || checkHash.length === 0) { return respondError(res, { status: 400, code: "HASH_REQUIRED", message: "hash is required" }); } var checkquerypath = "/api/file/upload"; if (hashAPIPath(checkquerypath) != "?hash=" + checkHash) { return respondError(res, { status: 400, code: "INVALID_HASH", message: "Invalid hash" }); } const appealData = req.body.appealData; const containerID = req.body?.containerID?.[0]; const casefolderID = req.body?.casefolderID?.[0]; const repOrAppeal = req.body.repOrAppeal || false; if ( typeof containerID === "undefined" || containerID.length === 0 || typeof casefolderID === "undefined" || casefolderID.length === 0 ) { return respondError(res, { status: 400, code: "MISSING_REQUIRED_BODY", message: "containerID and casefolderID are required" }); } return ( repOrAppeal ? createRepBlob(appealData, containerID, casefolderID) : createBlob(appealData, containerID, casefolderID) ) .then((data) => { return respondSuccess(res, { data }); }) .catch(() => { return respondError(res, { status: 400, code: "UPLOAD_FAILED", message: "Failed to upload blob" }); }); }); export const config = { api: { bodyParser: false } }; export default ApiProxy;