TASK22102: slice7 complex file handler contract closeout

This commit is contained in:
2026-03-17 13:25:51 +00:00
parent 98184b65df
commit 91890f4d73
4 changed files with 109 additions and 67 deletions
+22 -15
View File
@@ -3,6 +3,7 @@ import { downloadFile } from "../../../actions/azurestorage";
import nextConnect from "next-connect";
import { hashAPIPath } from "../../../actions/core/hash";
import middleware from "../middleware/middleware";
import { respondError } from "../middleware/apiResponse";
const ApiProxy = nextConnect();
@@ -24,7 +25,11 @@ ApiProxy.get(async (req, res) => {
typeof checkHash === "undefined" ||
checkHash.length === 0
) {
return res.status(400).json();
return respondError(res, {
status: 400,
code: "MISSING_REQUIRED_QUERY",
message: "container, casefolderID, blobname and hash are required"
});
}
var checkquerypath =
@@ -36,24 +41,26 @@ ApiProxy.get(async (req, res) => {
blobName.trim();
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
return res.status(400).json();
return respondError(res, {
status: 400,
code: "INVALID_HASH",
message: "Invalid hash"
});
}
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const bloblocation =
casefolderID + (blobName.indexOf(".json") > 0 ? "/" : "/files/");
const bloblocation =
casefolderID + (blobName.indexOf(".json") > 0 ? "/" : "/files/");
const downloaded = await downloadFile(
containerName,
bloblocation + decodeURI(blobName)
);
const downloaded = await downloadFile(
containerName,
bloblocation + decodeURI(blobName)
);
res.setHeader(
"content-disposition",
"attachment; filename=" + decodeURI(blobName)
);
return res.status(200).send(downloaded);
}
res.setHeader(
"content-disposition",
"attachment; filename=" + decodeURI(blobName)
);
return res.status(200).send(downloaded);
});
async function streamToBuffer(readableStream) {