(e)
| 60 | }; |
| 61 | |
| 62 | const handleFileUpload = async (e) => { |
| 63 | props.setIsTour && props.setIsTour(false); |
| 64 | const file = e.target.files[0]; |
| 65 | if (!file) { |
| 66 | alert(t("please-select-pdf")); |
| 67 | return; |
| 68 | } |
| 69 | if (!file.type.includes("pdf")) { |
| 70 | alert(t("only-pdf-allowed")); |
| 71 | return; |
| 72 | } |
| 73 | const fileSize = |
| 74 | maxFileSize; |
| 75 | const pdfsize = file?.size; |
| 76 | const fileSizeBytes = fileSize * 1024 * 1024; |
| 77 | if (pdfsize > fileSizeBytes) { |
| 78 | alert(`${t("file-alert-1")} ${fileSize} MB`); |
| 79 | removeFile(e); |
| 80 | return; |
| 81 | } |
| 82 | try { |
| 83 | let uploadedPdfBytes = await getFileAsArrayBuffer(file); |
| 84 | try { |
| 85 | await isPdfPasswordProtected(uploadedPdfBytes); |
| 86 | uploadedPdfBytes = await clearAcroFields(uploadedPdfBytes); // best effort cleanup to prevent stale data |
| 87 | } catch (error) { |
| 88 | if (error?.message?.includes("is encrypted")) { |
| 89 | try { |
| 90 | const pdfFile = await decryptPdf(file, ""); |
| 91 | const pdfArrayBuffer = await getFileAsArrayBuffer(pdfFile); |
| 92 | uploadedPdfBytes = await clearAcroFields(pdfArrayBuffer); |
| 93 | } catch (err) { |
| 94 | if (err?.response?.status === 401) { |
| 95 | const password = prompt( |
| 96 | `PDF "${file.name}" is password-protected. Enter password:` |
| 97 | ); |
| 98 | if (password) { |
| 99 | try { |
| 100 | const pdfFile = await decryptPdf(file, password); |
| 101 | const pdfArrayBuffer = await getFileAsArrayBuffer(pdfFile); |
| 102 | uploadedPdfBytes = await clearAcroFields(pdfArrayBuffer); |
| 103 | // Upload the file to Parse Server |
| 104 | } catch (err) { |
| 105 | console.error("Incorrect password or decryption failed", err); |
| 106 | alert(t("incorrect-password-or-decryption-failed")); |
| 107 | return; |
| 108 | } |
| 109 | } else { |
| 110 | alert(t("provide-password")); |
| 111 | return; |
| 112 | } |
| 113 | } else { |
| 114 | console.error("Decryption error ", error); |
| 115 | alert(t("error-uploading-pdf")); |
| 116 | return; |
| 117 | } |
| 118 | } |
| 119 | } else { |
nothing calls this directly
no test coverage detected