TASK22224: larger parity bundle for reps and upload handlers
This commit is contained in:
@@ -33,7 +33,6 @@ import {
|
||||
downloadAllRepsFiles,
|
||||
getRepsBlobs
|
||||
} from "../../../actions/azurestorage";
|
||||
import _ from "lodash";
|
||||
import nextConnect from "next-connect";
|
||||
import middleware from "../middleware/middleware";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
@@ -44,10 +43,8 @@ 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 checkHash = req.query.hash;
|
||||
|
||||
if (
|
||||
typeof containerName === "undefined" ||
|
||||
@@ -62,9 +59,16 @@ ApiProxy.get(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
var checkquerypath = "/api/file/getrepsblob?container=" + containerName;
|
||||
const hashCandidatePaths = [
|
||||
"/api/file/getrepsblob?container=" + containerName,
|
||||
"/api/file/getrepsblob?container=" + encodeURIComponent(containerName)
|
||||
];
|
||||
|
||||
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
||||
const isHashValid = hashCandidatePaths.some(
|
||||
(candidatePath) => hashAPIPath(candidatePath) == "&hash=" + checkHash
|
||||
);
|
||||
|
||||
if (!isHashValid) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INVALID_HASH",
|
||||
@@ -72,23 +76,19 @@ ApiProxy.get(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
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"
|
||||
});
|
||||
try {
|
||||
const repsBlobs = await getRepsBlobs(containerName);
|
||||
const result = await downloadAllRepsFiles(containerName, repsBlobs);
|
||||
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;
|
||||
|
||||
+18
-21
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
createBlob,
|
||||
createRepBlob,
|
||||
uploadFile
|
||||
} from "../../../actions/azurestorage";
|
||||
import { createBlob, createRepBlob } from "../../../actions/azurestorage";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
@@ -13,7 +9,7 @@ const ApiProxy = nextConnect();
|
||||
ApiProxy.use(middleware);
|
||||
|
||||
ApiProxy.post(async (req, res) => {
|
||||
var checkHash = req.query.hash;
|
||||
const checkHash = req.query.hash;
|
||||
|
||||
if (typeof checkHash === "undefined" || checkHash.length === 0) {
|
||||
return respondError(res, {
|
||||
@@ -23,9 +19,12 @@ ApiProxy.post(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
var checkquerypath = "/api/file/upload";
|
||||
const hashCandidatePaths = ["/api/file/upload", "/api/file/upload?"];
|
||||
const isHashValid = hashCandidatePaths.some(
|
||||
(candidatePath) => hashAPIPath(candidatePath) == "?hash=" + checkHash
|
||||
);
|
||||
|
||||
if (hashAPIPath(checkquerypath) != "?hash=" + checkHash) {
|
||||
if (!isHashValid) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INVALID_HASH",
|
||||
@@ -51,21 +50,19 @@ ApiProxy.post(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
repOrAppeal
|
||||
try {
|
||||
const data = await (repOrAppeal
|
||||
? createRepBlob(appealData, containerID, casefolderID)
|
||||
: createBlob(appealData, containerID, casefolderID)
|
||||
)
|
||||
.then((data) => {
|
||||
return respondSuccess(res, { data });
|
||||
})
|
||||
.catch(() => {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "UPLOAD_FAILED",
|
||||
message: "Failed to upload blob"
|
||||
});
|
||||
: createBlob(appealData, containerID, casefolderID));
|
||||
|
||||
return respondSuccess(res, { data });
|
||||
} catch {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "UPLOAD_FAILED",
|
||||
message: "Failed to upload blob"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const config = {
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
createBlob,
|
||||
createRepBlob,
|
||||
uploadSingleFile
|
||||
} from "../../../actions/azurestorage";
|
||||
import { uploadSingleFile } from "../../../actions/azurestorage";
|
||||
|
||||
import nextConnect from "next-connect";
|
||||
import middleware from "../middleware/middleware";
|
||||
@@ -37,7 +33,7 @@ const ApiProxy = nextConnect();
|
||||
ApiProxy.use(middleware);
|
||||
|
||||
ApiProxy.post(async (req, res) => {
|
||||
var checkHash = req.query.hash;
|
||||
const checkHash = req.query.hash;
|
||||
|
||||
if (typeof checkHash === "undefined" || checkHash.length === 0) {
|
||||
return respondError(res, {
|
||||
@@ -47,9 +43,15 @@ ApiProxy.post(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
var checkquerypath = "/api/file/uploadsinglefile";
|
||||
const hashCandidatePaths = [
|
||||
"/api/file/uploadsinglefile",
|
||||
"/api/file/uploadsinglefile?"
|
||||
];
|
||||
const isHashValid = hashCandidatePaths.some(
|
||||
(candidatePath) => hashAPIPath(candidatePath) == "?hash=" + checkHash
|
||||
);
|
||||
|
||||
if (hashAPIPath(checkquerypath) != "?hash=" + checkHash) {
|
||||
if (!isHashValid) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INVALID_HASH",
|
||||
@@ -87,8 +89,8 @@ ApiProxy.post(async (req, res) => {
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
];
|
||||
|
||||
var allowedFilesFormData = {};
|
||||
var invalidFiles = []; // To store the names of invalid files
|
||||
const allowedFilesFormData = {};
|
||||
const invalidFiles = []; // To store the names of invalid files
|
||||
|
||||
for (const [fileName, fileDetails] of Object.entries(uploadedFiles)) {
|
||||
const file = fileDetails[0];
|
||||
|
||||
Reference in New Issue
Block a user