applied downloadable checkbox on submit of new appeal

This commit is contained in:
2026-03-16 13:58:02 +00:00
parent 72eafd0a8e
commit 7c84344d5d
9 changed files with 189 additions and 57 deletions
+8 -2
View File
@@ -11,7 +11,13 @@ ApiProxy.get(async (req, res) => {
return res.status(401).json();
}
const queryPath = req.query.path;
const rawQueryPath = req.query.path;
const queryPath =
typeof rawQueryPath === "string"
? rawQueryPath.split("?")[0]
: rawQueryPath;
const allowedPrefix = [
"/api/endpoint/getportallogin_api",
"/api/endpoint/deletemyrepresentations_api",
@@ -36,7 +42,7 @@ ApiProxy.get(async (req, res) => {
return res.status(400).json();
}
return res.status(200).json({ hash: hashAPIPath(queryPath) });
return res.status(200).json({ hash: hashAPIPath(rawQueryPath) });
});
export default ApiProxy;
+31 -2
View File
@@ -113,6 +113,7 @@ import { other_pdf } from "../../../components/pdftemplates/other_pdf";
export default async function handler(req, res) {
var checkHash = req.query.hash;
var appealType = req.query.appealType;
var isDownload = req.query?.download === "true";
let appealBodyObj =
typeof req.body === "string" ? JSON.parse(req.body) : req.body;
@@ -134,7 +135,11 @@ export default async function handler(req, res) {
return res.status(400).json();
}
checkquerypath = checkquerypath + "?appealType=" + appealType;
checkquerypath =
checkquerypath +
"?appealType=" +
appealType +
(isDownload ? "&download=true" : "");
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
return res.status(400).json();
@@ -196,6 +201,19 @@ export default async function handler(req, res) {
// ReactPDF.renderToStream();
const streamToBuffer = async (readableStream) => {
return new Promise((resolve, reject) => {
const chunks = [];
readableStream.on("data", (chunk) => {
chunks.push(
Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)
);
});
readableStream.on("end", () => resolve(Buffer.concat(chunks)));
readableStream.on("error", reject);
});
};
const renderedPDF = await ReactPDF.renderToStream(
<MyDocument docProps={blobProgress} pickListData={pickListData} />
);
@@ -214,11 +232,22 @@ export default async function handler(req, res) {
("0" + day).slice(-2) +
"_-_Appeal_Form";
const renderedPDFBuffer = await streamToBuffer(renderedPDF);
await createAppealPDFBlob(
renderedPDF,
renderedPDFBuffer,
containerID,
blobProgress.pinswg_name || blobProgress.caseObj.ticketnumber
).then((data) => {
if (isDownload) {
const filename = `${pdfFileName}.pdf`;
res.setHeader("Content-Type", "application/pdf");
res.setHeader(
"Content-Disposition",
`attachment; filename="${filename}"`
);
return res.status(200).send(renderedPDFBuffer);
}
return res.status(200).json({
status: "success",
data: data,