TASK22224: harden file/static endpoint contracts and phase21 coverage

This commit is contained in:
2026-03-23 16:40:39 +00:00
parent 78cac2cbb9
commit f8fba6a561
7 changed files with 352 additions and 127 deletions
+24 -29
View File
@@ -10,10 +10,10 @@ const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var casefolderID = req.query.casefolderID;
var blobName = req.query.blobname;
var checkHash = req.query.hash;
const containerName = req.query.container;
const casefolderID = req.query.casefolderID;
const blobName = req.query.blobname;
const checkHash = req.query.hash;
if (
typeof containerName === "undefined" ||
@@ -32,7 +32,7 @@ ApiProxy.get(async (req, res) => {
});
}
var checkquerypath =
const checkquerypath =
"/api/file/downloadblob?container=" +
containerName +
"&casefolderID=" +
@@ -48,34 +48,29 @@ ApiProxy.get(async (req, res) => {
});
}
const bloblocation =
casefolderID + (blobName.indexOf(".json") > 0 ? "/" : "/files/");
try {
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);
} catch (error) {
return respondError(res, {
status: 400,
code: "DOWNLOAD_BLOB_FAILED",
message: "Unable to download blob"
});
}
});
async function streamToBuffer(readableStream) {
return new Promise((resolve, reject) => {
const chunks = [];
readableStream.on("data", (data) => {
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
});
readableStream.on("end", () => {
resolve(Buffer.concat(chunks));
});
readableStream.on("error", reject);
});
}
export const config = {
api: {
bodyParser: false