TASK22102: slice7 complex file handler contract closeout
This commit is contained in:
@@ -3,6 +3,7 @@ import { downloadFile } from "../../../actions/azurestorage";
|
|||||||
import nextConnect from "next-connect";
|
import nextConnect from "next-connect";
|
||||||
import { hashAPIPath } from "../../../actions/core/hash";
|
import { hashAPIPath } from "../../../actions/core/hash";
|
||||||
import middleware from "../middleware/middleware";
|
import middleware from "../middleware/middleware";
|
||||||
|
import { respondError } from "../middleware/apiResponse";
|
||||||
|
|
||||||
const ApiProxy = nextConnect();
|
const ApiProxy = nextConnect();
|
||||||
|
|
||||||
@@ -24,7 +25,11 @@ ApiProxy.get(async (req, res) => {
|
|||||||
typeof checkHash === "undefined" ||
|
typeof checkHash === "undefined" ||
|
||||||
checkHash.length === 0
|
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 =
|
var checkquerypath =
|
||||||
@@ -36,24 +41,26 @@ ApiProxy.get(async (req, res) => {
|
|||||||
blobName.trim();
|
blobName.trim();
|
||||||
|
|
||||||
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
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 =
|
||||||
const bloblocation =
|
casefolderID + (blobName.indexOf(".json") > 0 ? "/" : "/files/");
|
||||||
casefolderID + (blobName.indexOf(".json") > 0 ? "/" : "/files/");
|
|
||||||
|
|
||||||
const downloaded = await downloadFile(
|
const downloaded = await downloadFile(
|
||||||
containerName,
|
containerName,
|
||||||
bloblocation + decodeURI(blobName)
|
bloblocation + decodeURI(blobName)
|
||||||
);
|
);
|
||||||
|
|
||||||
res.setHeader(
|
res.setHeader(
|
||||||
"content-disposition",
|
"content-disposition",
|
||||||
"attachment; filename=" + decodeURI(blobName)
|
"attachment; filename=" + decodeURI(blobName)
|
||||||
);
|
);
|
||||||
return res.status(200).send(downloaded);
|
return res.status(200).send(downloaded);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function streamToBuffer(readableStream) {
|
async function streamToBuffer(readableStream) {
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ import { finalComments_pdf } from "../../../components/pdftemplates/finalComment
|
|||||||
import { statement_pdf } from "../../../components/pdftemplates/statement_pdf";
|
import { statement_pdf } from "../../../components/pdftemplates/statement_pdf";
|
||||||
import { writtenStatement_pdf } from "../../../components/pdftemplates/writtenStatement_pdf";
|
import { writtenStatement_pdf } from "../../../components/pdftemplates/writtenStatement_pdf";
|
||||||
import { other_pdf } from "../../../components/pdftemplates/other_pdf";
|
import { other_pdf } from "../../../components/pdftemplates/other_pdf";
|
||||||
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||||
|
|
||||||
//const ApiProxy = nextConnect();
|
//const ApiProxy = nextConnect();
|
||||||
// ApiProxy.use(middleware);
|
// ApiProxy.use(middleware);
|
||||||
@@ -132,7 +133,12 @@ export default async function handler(req, res) {
|
|||||||
typeof casefolderID === "undefined" ||
|
typeof casefolderID === "undefined" ||
|
||||||
String(casefolderID).length === 0
|
String(casefolderID).length === 0
|
||||||
) {
|
) {
|
||||||
return res.status(400).json();
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "MISSING_REQUIRED_QUERY",
|
||||||
|
message:
|
||||||
|
"hash, appealType, containerID and casefolderID are required"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
checkquerypath =
|
checkquerypath =
|
||||||
@@ -142,7 +148,11 @@ export default async function handler(req, res) {
|
|||||||
(isDownload ? "&download=true" : "");
|
(isDownload ? "&download=true" : "");
|
||||||
|
|
||||||
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
||||||
return res.status(400).json();
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "INVALID_HASH",
|
||||||
|
message: "Invalid hash"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Document Component
|
// Create Document Component
|
||||||
@@ -238,20 +248,28 @@ export default async function handler(req, res) {
|
|||||||
renderedPDFBuffer,
|
renderedPDFBuffer,
|
||||||
containerID,
|
containerID,
|
||||||
blobProgress.pinswg_name || blobProgress.caseObj.ticketnumber
|
blobProgress.pinswg_name || blobProgress.caseObj.ticketnumber
|
||||||
).then((data) => {
|
)
|
||||||
if (isDownload) {
|
.then((data) => {
|
||||||
const filename = `${pdfFileName}.pdf`;
|
if (isDownload) {
|
||||||
res.setHeader("Content-Type", "application/pdf");
|
const filename = `${pdfFileName}.pdf`;
|
||||||
res.setHeader(
|
res.setHeader("Content-Type", "application/pdf");
|
||||||
"Content-Disposition",
|
res.setHeader(
|
||||||
`attachment; filename="${filename}"`
|
"Content-Disposition",
|
||||||
);
|
`attachment; filename="${filename}"`
|
||||||
return res.status(200).send(renderedPDFBuffer);
|
);
|
||||||
}
|
return res.status(200).send(renderedPDFBuffer);
|
||||||
return res.status(200).json({
|
}
|
||||||
status: "success",
|
return respondSuccess(res, {
|
||||||
data: data,
|
status: "success",
|
||||||
path: `/files/${pdfFileName}.pdf`
|
data: data,
|
||||||
|
path: `/files/${pdfFileName}.pdf`
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "GENERATE_APPEAL_PDF_FAILED",
|
||||||
|
message: "Failed to generate appeal PDF"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
import { hashAPIPath } from "../../../actions/core/hash";
|
import { hashAPIPath } from "../../../actions/core/hash";
|
||||||
import { getBlobs, getRepsFilesBlobs } from "../../../actions/azurestorage";
|
import { getBlobs, getRepsFilesBlobs } from "../../../actions/azurestorage";
|
||||||
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||||
|
|
||||||
import nextConnect from "next-connect";
|
import nextConnect from "next-connect";
|
||||||
import middleware from "../middleware/middleware";
|
import middleware from "../middleware/middleware";
|
||||||
@@ -52,7 +53,11 @@ ApiProxy.get(async (req, res) => {
|
|||||||
typeof checkHash === "undefined" ||
|
typeof checkHash === "undefined" ||
|
||||||
checkHash.length === 0
|
checkHash.length === 0
|
||||||
) {
|
) {
|
||||||
return res.status(400).json();
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "MISSING_REQUIRED_QUERY",
|
||||||
|
message: "container, casefolderID and hash are required"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkquerypath =
|
var checkquerypath =
|
||||||
@@ -62,20 +67,23 @@ ApiProxy.get(async (req, res) => {
|
|||||||
casefolderID;
|
casefolderID;
|
||||||
|
|
||||||
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
||||||
return res.status(400).json();
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "INVALID_HASH",
|
||||||
|
message: "Invalid hash"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
casefolderID.split("/").length > 1
|
const data =
|
||||||
? await getRepsFilesBlobs(
|
casefolderID.split("/").length > 1
|
||||||
containerName,
|
? await getRepsFilesBlobs(
|
||||||
casefolderID.split("/")[0],
|
containerName,
|
||||||
casefolderID.split("/")[1]
|
casefolderID.split("/")[0],
|
||||||
).then((data) => {
|
casefolderID.split("/")[1]
|
||||||
return res.status(200).json({ "value": [data] });
|
)
|
||||||
})
|
: await getBlobs(containerName, casefolderID);
|
||||||
: await getBlobs(containerName, casefolderID).then((data) => {
|
|
||||||
return res.status(200).json({ "value": [data] });
|
return respondSuccess(res, { "value": [data] });
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
|
|||||||
+31
-22
@@ -4,6 +4,7 @@ import {
|
|||||||
uploadFile
|
uploadFile
|
||||||
} from "../../../actions/azurestorage";
|
} from "../../../actions/azurestorage";
|
||||||
import { hashAPIPath } from "../../../actions/core/hash";
|
import { hashAPIPath } from "../../../actions/core/hash";
|
||||||
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||||
|
|
||||||
import nextConnect from "next-connect";
|
import nextConnect from "next-connect";
|
||||||
import middleware from "../middleware/middleware";
|
import middleware from "../middleware/middleware";
|
||||||
@@ -15,13 +16,21 @@ ApiProxy.post(async (req, res) => {
|
|||||||
var checkHash = req.query.hash;
|
var checkHash = req.query.hash;
|
||||||
|
|
||||||
if (typeof checkHash === "undefined" || checkHash.length === 0) {
|
if (typeof checkHash === "undefined" || checkHash.length === 0) {
|
||||||
return res.status(400).json();
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "HASH_REQUIRED",
|
||||||
|
message: "hash is required"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkquerypath = "/api/file/upload";
|
var checkquerypath = "/api/file/upload";
|
||||||
|
|
||||||
if (hashAPIPath(checkquerypath) != "?hash=" + checkHash) {
|
if (hashAPIPath(checkquerypath) != "?hash=" + checkHash) {
|
||||||
return res.status(400).json();
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "INVALID_HASH",
|
||||||
|
message: "Invalid hash"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const appealData = req.body.appealData;
|
const appealData = req.body.appealData;
|
||||||
@@ -35,28 +44,28 @@ ApiProxy.post(async (req, res) => {
|
|||||||
typeof casefolderID === "undefined" ||
|
typeof casefolderID === "undefined" ||
|
||||||
casefolderID.length === 0
|
casefolderID.length === 0
|
||||||
) {
|
) {
|
||||||
return res.status(400).json();
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "MISSING_REQUIRED_BODY",
|
||||||
|
message: "containerID and casefolderID are required"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
repOrAppeal
|
return (
|
||||||
? createRepBlob(appealData, containerID, casefolderID).then((data) => {
|
repOrAppeal
|
||||||
// Object.keys(req.files).length > 0 &&
|
? createRepBlob(appealData, containerID, casefolderID)
|
||||||
// uploadFile(req.files, containerID, casefolderID).then(
|
: createBlob(appealData, containerID, casefolderID)
|
||||||
// (data) => {
|
)
|
||||||
// return res.status(200).json({ data });
|
.then((data) => {
|
||||||
// }
|
return respondSuccess(res, { data });
|
||||||
// );
|
})
|
||||||
return res.status(200).json({ data });
|
.catch(() => {
|
||||||
})
|
return respondError(res, {
|
||||||
: createBlob(appealData, containerID, casefolderID).then((data) => {
|
status: 400,
|
||||||
// Object.keys(req.files).length > 0 &&
|
code: "UPLOAD_FAILED",
|
||||||
// uploadFile(req.files, containerID, casefolderID).then(
|
message: "Failed to upload blob"
|
||||||
// (data) => {
|
});
|
||||||
// return res.status(200).json({ data });
|
});
|
||||||
// }
|
|
||||||
// );
|
|
||||||
return res.status(200).json({ data });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
|
|||||||
Reference in New Issue
Block a user