From 9dd190d65b18429ded79213bdfdf91a88aac0062 Mon Sep 17 00:00:00 2001 From: enes Date: Fri, 11 Oct 2024 16:16:59 +0200 Subject: [PATCH 1/2] fix: add files and marked to sign page exports Skip marked if the file contains no marks --- src/pages/sign/index.tsx | 14 ++------------ src/utils/file.ts | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index dbbcd98..55276de 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -771,14 +771,9 @@ export const SignPage = () => { 2 ) - const zip = new JSZip() - + const zip = await getZipWithFiles(meta, files) zip.file('meta.json', stringifiedMeta) - for (const [fileName, file] of Object.entries(files)) { - zip.file(`files/${fileName}`, await file.arrayBuffer()) - } - const arrayBuffer = await zip .generateAsync({ type: 'arraybuffer', @@ -807,16 +802,11 @@ export const SignPage = () => { const handleEncryptedExport = async () => { if (Object.entries(files).length === 0 || !meta) return - const zip = new JSZip() - const stringifiedMeta = JSON.stringify(meta, null, 2) + const zip = await getZipWithFiles(meta, files) zip.file('meta.json', stringifiedMeta) - for (const [fileName, file] of Object.entries(files)) { - zip.file(`files/${fileName}`, await file.arrayBuffer()) - } - const arrayBuffer = await zip .generateAsync({ type: 'arraybuffer', diff --git a/src/utils/file.ts b/src/utils/file.ts index 84b30fc..c08d5e7 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -20,7 +20,7 @@ export const getZipWithFiles = async ( for (const [fileName, file] of Object.entries(files)) { // Handle PDF Files, add marks - if (file.isPdf) { + if (file.isPdf && fileName in marksByFileNamePage) { const blob = await addMarks(file, marksByFileNamePage[fileName]) zip.file(`marked/${fileName}`, blob) } From cc382f072643918e83c399374bfe5ff77af794e4 Mon Sep 17 00:00:00 2001 From: enes Date: Fri, 11 Oct 2024 16:43:55 +0200 Subject: [PATCH 2/2] fix: show error if decrypt fails --- src/pages/sign/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index 55276de..dd31938 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -536,7 +536,11 @@ export const SignPage = () => { setIsLoading(true) const arrayBuffer = await decrypt(selectedFile) - if (!arrayBuffer) return + if (!arrayBuffer) { + setIsLoading(false) + toast.error('Error decrypting file') + return + } handleDecryptedArrayBuffer(arrayBuffer) }