TASK22102: slice5 larger file handler contract cleanup

This commit is contained in:
2026-03-17 13:16:48 +00:00
parent e68319f16c
commit 3048df3cd9
5 changed files with 112 additions and 20 deletions
+22 -5
View File
@@ -8,6 +8,7 @@ import nextConnect from "next-connect";
import middleware from "../middleware/middleware";
import { consoleLogger } from "../../../actions/core/logger";
import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
import { fileTypeFromBuffer } from "file-type";
import fs from "fs";
import path from "path";
@@ -39,13 +40,21 @@ ApiProxy.post(async (req, res) => {
var checkHash = req.query.hash;
if (typeof checkHash === "undefined" || checkHash.length === 0) {
return res.status(400).json();
return respondError(res, {
status: 400,
code: "HASH_REQUIRED",
message: "hash is required"
});
}
var checkquerypath = "/api/file/uploadsinglefile";
if (hashAPIPath(checkquerypath) != "?hash=" + checkHash) {
return res.status(400).json();
return respondError(res, {
status: 400,
code: "INVALID_HASH",
message: "Invalid hash"
});
}
const containerID = req.body?.containerID?.[0];
@@ -57,7 +66,11 @@ ApiProxy.post(async (req, res) => {
typeof casefolderID === "undefined" ||
casefolderID.length === 0
) {
return res.status(400).json();
return respondError(res, {
status: 400,
code: "MISSING_REQUIRED_BODY",
message: "containerID and casefolderID are required"
});
}
const uploadedFiles = req.files || {};
@@ -126,10 +139,14 @@ ApiProxy.post(async (req, res) => {
containerID,
casefolderID
);
return res.status(200).json({ data, invalidFiles });
return respondSuccess(res, { data, invalidFiles });
} catch (error) {
consoleLogger(error);
return res.status(500).json({ error: "Failed to upload files" });
return respondError(res, {
status: 500,
code: "UPLOAD_SINGLE_FILE_FAILED",
message: "Failed to upload files"
});
}
});