MCPcopy Create free account
hub / github.com/OpenSignLabs/OpenSign / DownloadPdfZip

Function DownloadPdfZip

apps/OpenSign/src/primitives/DownloadPdfZip.jsx:14–150  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

12import { saveAs } from "file-saver";
13
14function DownloadPdfZip(props) {
15 const appName =
16 "OpenSign™";
17 const { t } = useTranslation();
18 const [selectType, setSelectType] = useState(1);
19 const [isDownloading, setIsDownloading] = useState(false);
20 const downloadType = [
21 { id: 1, label: t("download-pdf") },
22 { id: 2, label: t("pdf-certificate") }
23 ];
24
25 const handleDownload = async () => {
26 if (selectType === 1) {
27 await handleDownloadPdf(
28 props.pdfDetails,
29 setIsDownloading,
30 props?.pdfBase64
31 );
32 setSelectType(1);
33 props.setIsDownloadModal(false);
34 } else if (selectType === 2) {
35 setIsDownloading("pdf");
36 const zip = new JSZip();
37 const pdfDetails = props.pdfDetails;
38 const pdfName =
39 pdfDetails?.[0]?.Name?.length > 100
40 ? pdfDetails?.[0]?.Name?.slice(0, 100)
41 : pdfDetails?.[0]?.Name || "Document";
42 const pdfUrl = pdfDetails?.[0]?.SignedUrl || "";
43
44 try {
45 // Fetch the first PDF (Signed Document)
46 const docId = pdfDetails?.[0]?.objectId || "";
47 const signedUrl = await getSignedUrl(
48 pdfUrl,
49 docId,
50 );
51 const pdf1Response = await fetch(signedUrl);
52 if (!pdf1Response.ok) {
53 throw new Error(`Failed to fetch PDF: ${signedUrl}`);
54 }
55 const pdf1Blob = await pdf1Response.blob();
56 const isZip = true;
57 // Fetch the Certificate (or generate its URL dynamically)
58 const certificateUrl = await handleDownloadCertificate(
59 pdfDetails,
60 setIsDownloading,
61 isZip
62 );
63 const pdf2Response = await fetch(certificateUrl);
64 if (!pdf2Response.ok) {
65 throw new Error(`Failed to fetch certificate PDF: ${certificateUrl}`);
66 }
67 const pdf2Blob = await pdf2Response.blob();
68 // Add files to ZIP
69 zip.file(
70 `${fileNameWithUnderscore(pdfName)}_signed_by_${appName}.pdf`,
71 pdf1Blob

Callers

nothing calls this directly

Calls 1

handleDownloadFunction · 0.70

Tested by

no test coverage detected