TASK22224: harden getbloblist and getprogressobjblob parity
This commit is contained in:
@@ -40,10 +40,9 @@ const ApiProxy = nextConnect();
|
||||
ApiProxy.use(middleware);
|
||||
|
||||
ApiProxy.get(async (req, res) => {
|
||||
var containerName = req.query.container;
|
||||
var casefolderID = req.query.casefolderID;
|
||||
|
||||
var checkHash = req.query.hash;
|
||||
const containerName = req.query.container;
|
||||
const casefolderID = req.query.casefolderID;
|
||||
const checkHash = req.query.hash;
|
||||
|
||||
if (
|
||||
typeof containerName === "undefined" ||
|
||||
@@ -60,13 +59,24 @@ ApiProxy.get(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
var checkquerypath =
|
||||
"/api/file/getbloblist?container=" +
|
||||
containerName +
|
||||
"&casefolderID=" +
|
||||
casefolderID;
|
||||
const casefolderIDTrimmed = casefolderID.trim();
|
||||
|
||||
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
||||
const hashCandidatePaths = [
|
||||
"/api/file/getbloblist?container=" +
|
||||
containerName +
|
||||
"&casefolderID=" +
|
||||
casefolderIDTrimmed,
|
||||
"/api/file/getbloblist?container=" +
|
||||
containerName +
|
||||
"&casefolderID=" +
|
||||
encodeURIComponent(casefolderIDTrimmed)
|
||||
];
|
||||
|
||||
const isHashValid = hashCandidatePaths.some(
|
||||
(candidatePath) => hashAPIPath(candidatePath) == "&hash=" + checkHash
|
||||
);
|
||||
|
||||
if (!isHashValid) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INVALID_HASH",
|
||||
@@ -74,16 +84,24 @@ ApiProxy.get(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const data =
|
||||
casefolderID.split("/").length > 1
|
||||
? await getRepsFilesBlobs(
|
||||
containerName,
|
||||
casefolderID.split("/")[0],
|
||||
casefolderID.split("/")[1]
|
||||
)
|
||||
: await getBlobs(containerName, casefolderID);
|
||||
try {
|
||||
const data =
|
||||
casefolderIDTrimmed.split("/").length > 1
|
||||
? await getRepsFilesBlobs(
|
||||
containerName,
|
||||
casefolderIDTrimmed.split("/")[0],
|
||||
casefolderIDTrimmed.split("/")[1]
|
||||
)
|
||||
: await getBlobs(containerName, casefolderIDTrimmed);
|
||||
|
||||
return respondSuccess(res, { "value": [data] });
|
||||
return respondSuccess(res, { "value": [data] });
|
||||
} catch (error) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "GET_BLOB_LIST_FAILED",
|
||||
message: "Failed to retrieve blob list"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const config = {
|
||||
|
||||
@@ -12,10 +12,9 @@ const ApiProxy = nextConnect();
|
||||
ApiProxy.use(middleware);
|
||||
|
||||
ApiProxy.get(async (req, res) => {
|
||||
var containerName = req.query.container;
|
||||
var casefolderID = req.query.casefolderID;
|
||||
|
||||
var checkHash = req.query.hash;
|
||||
const containerName = req.query.container;
|
||||
const casefolderID = req.query.casefolderID;
|
||||
const checkHash = req.query.hash;
|
||||
|
||||
if (
|
||||
typeof containerName === "undefined" ||
|
||||
@@ -32,13 +31,24 @@ ApiProxy.get(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
var checkquerypath =
|
||||
"/api/file/getprogressobjblob?container=" +
|
||||
containerName +
|
||||
"&casefolderID=" +
|
||||
casefolderID;
|
||||
const casefolderIDTrimmed = casefolderID.trim();
|
||||
|
||||
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
||||
const hashCandidatePaths = [
|
||||
"/api/file/getprogressobjblob?container=" +
|
||||
containerName +
|
||||
"&casefolderID=" +
|
||||
casefolderIDTrimmed,
|
||||
"/api/file/getprogressobjblob?container=" +
|
||||
containerName +
|
||||
"&casefolderID=" +
|
||||
encodeURIComponent(casefolderIDTrimmed)
|
||||
];
|
||||
|
||||
const isHashValid = hashCandidatePaths.some(
|
||||
(candidatePath) => hashAPIPath(candidatePath) == "&hash=" + checkHash
|
||||
);
|
||||
|
||||
if (!isHashValid) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INVALID_HASH",
|
||||
@@ -46,13 +56,24 @@ ApiProxy.get(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
await getProgressBlobs(containerName, casefolderID)
|
||||
.then((data) => {
|
||||
return downloadProgressFile(containerName, data.path, casefolderID);
|
||||
})
|
||||
.then((data) => {
|
||||
return respondSuccess(res, data);
|
||||
try {
|
||||
const progressBlob = await getProgressBlobs(
|
||||
containerName,
|
||||
casefolderIDTrimmed
|
||||
);
|
||||
const data = await downloadProgressFile(
|
||||
containerName,
|
||||
progressBlob.path,
|
||||
casefolderIDTrimmed
|
||||
);
|
||||
return respondSuccess(res, data);
|
||||
} catch (error) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "GET_PROGRESS_OBJ_BLOB_FAILED",
|
||||
message: "Failed to retrieve progress blob"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const config = {
|
||||
|
||||
Reference in New Issue
Block a user