TASK22102: slice6 blob crud and retrieval contract cleanup
This commit is contained in:
@@ -38,6 +38,7 @@ import nextConnect from "next-connect";
|
||||
import middleware from "../middleware/middleware";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
const ApiProxy = nextConnect();
|
||||
ApiProxy.use(middleware);
|
||||
@@ -54,32 +55,40 @@ 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 and hash are required"
|
||||
});
|
||||
}
|
||||
|
||||
var checkquerypath = "/api/file/getrepsblob?container=" + containerName;
|
||||
|
||||
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 blobObj = await getRepsBlobs(containerName)
|
||||
.then(async (data) => {
|
||||
return data;
|
||||
})
|
||||
.then(async (data) => {
|
||||
let result = await downloadAllRepsFiles(containerName, data);
|
||||
|
||||
return res
|
||||
.setHeader("Cache-Control", "no-store")
|
||||
.status(200)
|
||||
.json(result);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
const blobObj = await getRepsBlobs(containerName)
|
||||
.then(async (data) => {
|
||||
return data;
|
||||
})
|
||||
.then(async (data) => {
|
||||
let result = await downloadAllRepsFiles(containerName, data);
|
||||
res.setHeader("Cache-Control", "no-store");
|
||||
return respondSuccess(res, result);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "GET_REPS_BLOB_FAILED",
|
||||
message: "Failed to retrieve representation blobs"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export default ApiProxy;
|
||||
|
||||
Reference in New Issue
Block a user