MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / handleDownloadPdf

Function handleDownloadPdf

apps/OpenSign/src/constant/Utils.js:3012–3045  ·  view source on GitHub ↗
(
  pdfDetails,
  setIsDownloading,
  pdfBase64
)

Source from the content-addressed store, hash-verified

3010};
3011//handle download signed pdf
3012export const handleDownloadPdf = async (
3013 pdfDetails,
3014 setIsDownloading,
3015 pdfBase64
3016) => {
3017 const pdfName =
3018 pdfDetails?.[0]?.Name?.length > 100
3019 ? pdfDetails?.[0]?.Name?.slice(0, 100)
3020 : pdfDetails?.[0]?.Name || "Document";
3021 const isCompleted = pdfDetails?.[0]?.IsCompleted || false;
3022 const formatId = pdfDetails?.[0]?.ExtUserPtr?.DownloadFilenameFormat;
3023 const docName = buildDownloadFilename(formatId, {
3024 docName: pdfName,
3025 email: pdfDetails?.[0]?.ExtUserPtr?.Email,
3026 isSigned: isCompleted
3027 });
3028 if (pdfBase64) {
3029 await fetchBase64(pdfBase64, docName);
3030 setIsDownloading && setIsDownloading("");
3031 } else {
3032 const pdfUrl = pdfDetails?.[0]?.SignedUrl || pdfDetails?.[0]?.URL;
3033 setIsDownloading && setIsDownloading("pdf");
3034 const docId = pdfDetails?.[0]?.objectId || "";
3035 try {
3036 const url = await getSignedUrl(pdfUrl, docId);
3037 await fetchUrl(url, docName);
3038 setIsDownloading && setIsDownloading("");
3039 } catch (err) {
3040 console.log("err in getsignedurl", err);
3041 setIsDownloading("");
3042 alert(i18n.t("something-went-wrong-mssg"));
3043 }
3044 }
3045};
3046
3047export function fileNameWithUnderscore(pdfName) {
3048 // Replace spaces with underscore

Callers 4

handleDownloadDocFunction · 0.90
handleMenuItemClickFunction · 0.90
handleDownloadFunction · 0.90
handleDownloadFunction · 0.90

Calls 4

buildDownloadFilenameFunction · 0.90
fetchBase64Function · 0.85
fetchUrlFunction · 0.85
getSignedUrlFunction · 0.70

Tested by

no test coverage detected