🔥 The free & Open Source DocuSign alternative
JavaScript digital-signaturedocument-signingdocusign-alternativedocusign-freee-signatureelectronic-signatureelectronic-signaturesesignesignaturehacktoberfestjavascriptlegaltechmongodbnodejsopen-sourcepdf-signpdf-signaturereactjsself-hostedsign-pdf-files
feat: add zip file to dowload pdf and certificate in all download option of completed pdf
RaktimaNXGe559d037c3f1
diff --git a/apps/OpenSign/src/components/pdf/EmailComponent.js b/apps/OpenSign/src/components/pdf/EmailComponent.jsindex e294f6375..6a7e7e940 100644--- a/apps/OpenSign/src/components/pdf/EmailComponent.js+++ b/apps/OpenSign/src/components/pdf/EmailComponent.js@@ -1,6 +1,6 @@import React, { useState } from "react";import axios from "axios";-import { handleDownloadPdf, handleToPrint } from "../../constant/Utils";+import { handleToPrint } from "../../constant/Utils";import { themeColor, emailRegex } from "../../constant/const";import Loader from "../../primitives/Loader";import ModalUi from "../../primitives/ModalUi";@@ -15,7 +15,8 @@ function EmailComponent({sender,setIsAlert,extUserId,- activeMailAdapter+ activeMailAdapter,+ setIsDownloadModal}) {const { t } = useTranslation();const [emailList, setEmailList] = useState([]);@@ -129,6 +130,11 @@ function EmailComponent({}}};+ const handleClose = () => {+ setIsEmail(false);+ setEmailValue("");+ setEmailList([]);+ };return (<div>{/* isEmail */}@@ -165,7 +171,10 @@ function EmailComponent({)}<buttonclassName="op-btn op-btn-primary op-btn-sm text-[15px] ml-2"- onClick={() => handleDownloadPdf(pdfDetails, setIsDownloading)}+ onClick={() => {+ handleClose();+ setIsDownloadModal(true);+ }}><i className="fa-light fa-download" aria-hidden="true"></i>{t("download")}@@ -261,11 +270,7 @@ function EmailComponent({<buttontype="button"className="op-btn op-btn-ghost ml-2"- onClick={() => {- setIsEmail(false);- setEmailValue("");- setEmailList([]);- }}+ onClick={() => handleClose()}>{t("close")}</button>diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.jsindex 06bbdae76..6ab64c962 100644--- a/apps/OpenSign/src/constant/Utils.js+++ b/apps/OpenSign/src/constant/Utils.js@@ -2038,6 +2038,13 @@ export const fetchUrl = async (url, pdfName) => {console.error("Error downloading the file:", error);}};+export const getSignedUrl = async (pdfUrl, docId) => {+ const signedUrl = await Parse.Cloud.run("getsignedurl", {+ url: pdfUrl,+ docId: docId || ""+ });+ return signedUrl;+};//handle download signed pdfexport const handleDownloadPdf = async (pdfDetails, setIsDownloading) => {const pdfName = pdfDetails[0] && pdfDetails[0]?.Name;@@ -2045,19 +2052,7 @@ export const handleDownloadPdf = async (pdfDetails, setIsDownloading) => {setIsDownloading("pdf");const docId = !pdfDetails?.[0]?.IsEnableOTP ? pdfDetails?.[0]?.objectId : "";try {- // const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });- const axiosRes = await axios.post(- `${localStorage.getItem("baseUrl")}/functions/getsignedurl`,- { url: pdfUrl, docId: docId },- {- headers: {- "content-type": "Application/json",- "X-Parse-Application-Id": localStorage.getItem("parseAppId"),- "X-Parse-Session-Token": localStorage.getItem("accesstoken")- }- }- );- const url = axiosRes.data.result;+ const url = await getSignedUrl(pdfUrl, docId);await fetchUrl(url, pdfName);setIsDownloading("");} catch (err) {@@ -2165,6 +2160,7 @@ export const handleDownloadCertificate = async (await fetch(doc?.CertificateUrl);const certificateUrl = doc?.CertificateUrl;if (isZip) {+ setIsDownloading("");return certificateUrl;} else {saveAs(certificateUrl, `Certificate_signed_by_OpenSignâ„¢.pdf`);diff --git a/apps/OpenSign/src/pages/PdfRequestFiles.js b/apps/OpenSign/src/pages/PdfRequestFiles.jsindex 301e5cedc..2e9e4a5c7 100644--- a/apps/OpenSign/src/pages/PdfRequestFiles.js+++ b/apps/OpenSign/src/pages/PdfRequestFiles.js@@ -28,7 +28,6 @@ import {contractUsers,handleSendOTP,contactBook,- handleDownloadPdf,handleToPrint,handleDownloadCertificate,getDefaultSignature,@@ -2000,9 +1999,13 @@ function PdfRequestFiles(props) {<buttontype="button"className="font-[500] text-[13px] mr-[5px] op-btn op-btn-primary"- onClick={() =>- handleDownloadPdf(pdfDetails, setIsDownloading)- }+ onClick={() => {+ setIsCompleted((prev) => ({+ ...prev,+ isModal: false+ }));+ setIsDownloadModal(true);+ }}><iclassName="fa-light fa-download"@@ -2213,6 +2216,7 @@ function PdfRequestFiles(props) {setIsDownloadModal={setIsDownloadModal}isDownloadModal={isDownloadModal}pdfDetails={pdfDetails}+ isDocId={true}/></>)}diff --git a/apps/OpenSign/src/pages/SignyourselfPdf.js b/apps/OpenSign/src/pages/SignyourselfPdf.jsindex 3242a6859..2f63563ef 100644--- a/apps/OpenSign/src/pages/SignyourselfPdf.js+++ b/apps/OpenSign/src/pages/SignyourselfPdf.js@@ -1336,6 +1336,7 @@ function SignYourSelf() {setIsAlert={setIsAlert}extUserId={extUserId}activeMailAdapter={activeMailAdapter}+ setIsDownloadModal={setIsDownloadModal}/>{/* pdf header which contain funish back button */}<Header@@ -1464,6 +1465,7 @@ function SignYourSelf() {setIsDownloadModal={setIsDownloadModal}isDownloadModal={isDownloadModal}pdfDetails={pdfDetails}+ isDocId={true}/><TextFontSettingisTextSetting={isTextSetting}diff --git a/apps/OpenSign/src/primitives/DownloadPdfZip.js b/apps/OpenSign/src/primitives/DownloadPdfZip.jsindex 0f7411677..4f9a5116c 100644--- a/apps/OpenSign/src/primitives/DownloadPdfZip.js+++ b/apps/OpenSign/src/primitives/DownloadPdfZip.js@@ -2,6 +2,7 @@ import React, { useState } from "react";import { useTranslation } from "react-i18next";import ModalUi from "./ModalUi";import {+ getSignedUrl,handleDownloadCertificate,handleDownloadPdf,sanitizeFileName@@ -21,8 +22,11 @@ function DownloadPdfZip(props) {const handleDownload = async () => {if (selectType === 1) {- handleDownloadPdf(props.pdfDetails, setIsDownloading);+ await handleDownloadPdf(props.pdfDetails, setIsDownloading);+ setSelectType(1);+ props.setIsDownloadModal(false);} else if (selectType === 2) {+ setIsDownloading("pdf");const zip = new JSZip();const pdfDetails = props.pdfDetails;const pdfName = pdfDetails?.[0]?.Name || "Document";@@ -30,9 +34,14 @@ function DownloadPdfZip(props) {try {// Fetch the first PDF (Signed Document)- const pdf1Response = await fetch(pdfUrl);+ const docId =+ props.isDocId && !pdfDetails?.[0]?.IsEnableOTP+ ? pdfDetails?.[0]?.objectId+ : "";+ const signedUrl = await getSignedUrl(pdfUrl, docId);+ const pdf1Response = await fetch(signedUrl);if (!pdf1Response.ok) {- throw new Error(`Failed to fetch PDF: ${pdfUrl}`);+ throw new Error(`Failed to fetch PDF: ${signedUrl}`);}const pdf1Blob = await pdf1Response.blob();@@ -56,14 +65,16 @@ function DownloadPdfZip(props) {// Generate the ZIP and trigger downloadconst zipBlob = await zip.generateAsync({ type: "blob" });- saveAs(zipBlob, "pdf-files.zip");+ saveAs(zipBlob, `${sanitizeFileName(pdfName)}.zip`);setSelectType(1);props.setIsDownloadModal(false);+ setIsDownloading("");} catch (error) {console.error("Error creating ZIP file:", error);}}};+ console.log("isDownloading", isDownloading);return (<ModalUiisOpen={props.isDownloadModal}diff --git a/apps/OpenSign/src/primitives/GetReportDisplay.js b/apps/OpenSign/src/primitives/GetReportDisplay.jsindex 15ebfcde1..23a33e7d8 100644--- a/apps/OpenSign/src/primitives/GetReportDisplay.js+++ b/apps/OpenSign/src/primitives/GetReportDisplay.js@@ -14,6 +14,7 @@ import {checkIsSubscribed,copytoData,fetchUrl,+ getSignedUrl,replaceMailVaribles} from "../constant/Utils";import Confetti from "react-confetti";@@ -30,6 +31,7 @@ import SubscribeCard from "./SubscribeCard";import { validplan } from "../json/plansArr";import { serverUrl_fn } from "../constant/appinfo";import { useTranslation } from "react-i18next";+import DownloadPdfZip from "./DownloadPdfZip";const ReportTable = (props) => {const { t } = useTranslation();@@ -71,6 +73,7 @@ const ReportTable = (props) => {const [isSubscribe, setIsSubscribe] = useState(true);const [isModal, setIsModal] = useState({});const [reason, setReason] = useState("");+ const [isDownloadModal, setIsDownloadModal] = useState(false);const Extand_Class = localStorage.getItem("Extand_Class");const extClass = Extand_Class && JSON.parse(Extand_Class);const startIndex = (currentPage - 1) * props.docPerPage;@@ -649,10 +652,15 @@ const ReportTable = (props) => {setActLoader({ [`${item.objectId}`]: true });const url = item?.SignedUrl || item?.URL || "";const pdfName = item?.Name || "exported_file";+ const isCompleted = item?.IsCompleted || false;if (url) {try {- const signedUrl = await Parse.Cloud.run("getsignedurl", { url: url });- await fetchUrl(signedUrl, pdfName);+ if (isCompleted) {+ setIsDownloadModal({ [item.objectId]: true });+ } else {+ const signedUrl = await getSignedUrl(url);+ await fetchUrl(signedUrl, pdfName);+ }setActLoader({});} catch (err) {console.log("err in getsignedurl", err);@@ -2107,6 +2115,14 @@ const ReportTable = (props) => {</div></ModalUi>)}+ {isDownloadModal[item.objectId] && (+ <DownloadPdfZip+ setIsDownloadModal={setIsDownloadModal}+ isDownloadModal={isDownloadModal[item.objectId]}+ pdfDetails={[item]}+ isDocId={false}+ />+ )}</td></tr>)diff --git a/apps/OpenSignServer/cloud/parsefunction/reportsJson.js b/apps/OpenSignServer/cloud/parsefunction/reportsJson.jsindex 49f5b42e4..a02284780 100644--- a/apps/OpenSignServer/cloud/parsefunction/reportsJson.js+++ b/apps/OpenSignServer/cloud/parsefunction/reportsJson.js@@ -139,6 +139,7 @@ export default function reportJson(id, userId) {'TimeToCompleteDays','Placeholders','IsSignyourself',+ 'IsCompleted',],};// declined documents report