From fda1d6bc73ae4a93052e9642ae3a0570dbde3a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Sz=C3=BCcs?= <127139797+balazs-szucs@users.noreply.github.com> Date: Sat, 11 Oct 2025 19:23:44 +0200 Subject: [PATCH] fix(repair): suppress corrupted PDF error/warning banner on repair page (#4434) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description of Changes Updated JS/HTML to ignore PDF corruption warning on repair-pdf html, since if user is already there, it may be safely assumed that the user is well-aware about said PDF corruption, and does not actually benefit from the information Closes: #4432 --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --------- Signed-off-by: Balázs Szücs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/main/resources/static/js/DecryptFiles.js | 14 +++++++++----- .../src/main/resources/static/js/downloader.js | 13 +++++++++---- .../main/resources/templates/fragments/common.html | 1 + 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/core/src/main/resources/static/js/DecryptFiles.js b/app/core/src/main/resources/static/js/DecryptFiles.js index 0e5b58a92..e569d8839 100644 --- a/app/core/src/main/resources/static/js/DecryptFiles.js +++ b/app/core/src/main/resources/static/js/DecryptFiles.js @@ -128,11 +128,15 @@ export class DecryptFile { (error.message && error.message.includes('Invalid PDF structure'))) { // Handle corrupted PDF files console.error('Corrupted PDF detected:', error); - this.showErrorBanner( - `${window.stirlingPDF.pdfCorruptedMessage.replace('{0}', file.name)}`, - error.stack || '', - `${window.stirlingPDF.tryRepairMessage}` - ); + if (window.stirlingPDF.currentPage !== 'repair') { + this.showErrorBanner( + `${window.stirlingPDF.pdfCorruptedMessage.replace('{0}', file.name)}`, + error.stack || '', + `${window.stirlingPDF.tryRepairMessage}` + ); + } else { + console.log('Suppressing corrupted PDF warning banner on repair page'); + } throw new Error('PDF file is corrupted.'); } diff --git a/app/core/src/main/resources/static/js/downloader.js b/app/core/src/main/resources/static/js/downloader.js index 47e1b06af..9e074be5e 100644 --- a/app/core/src/main/resources/static/js/downloader.js +++ b/app/core/src/main/resources/static/js/downloader.js @@ -249,10 +249,15 @@ (error.message && error.message.includes('Invalid PDF structure'))) { // Handle corrupted PDF files console.log(`Corrupted PDF detected: ${file.name}`, error); - showErrorBanner( - `${window.stirlingPDF.pdfCorruptedMessage.replace('{0}', file.name)}`, - `${window.stirlingPDF.tryRepairMessage}` - ); + if (window.stirlingPDF.currentPage !== 'repair') { + showErrorBanner( + `${window.stirlingPDF.pdfCorruptedMessage.replace('{0}', file.name)}`, + `${window.stirlingPDF.tryRepairMessage}` + ); + } else { + // On repair page, suppress banner; user already knows and is repairing + console.log('Suppressing corrupted PDF banner on repair page'); + } throw error; } else { console.log(`Error loading PDF: ${file.name}`, error); diff --git a/app/core/src/main/resources/templates/fragments/common.html b/app/core/src/main/resources/templates/fragments/common.html index d3b888a1d..49c958914 100644 --- a/app/core/src/main/resources/templates/fragments/common.html +++ b/app/core/src/main/resources/templates/fragments/common.html @@ -380,6 +380,7 @@ window.stirlingPDF.uploadLimitExceededPlural = /*[[#{uploadLimitExceededPlural}]]*/ 'are too large. Maximum allowed size is'; window.stirlingPDF.pdfCorruptedMessage = /*[[#{error.pdfInvalid}]]*/ 'The PDF file "{0}" appears to be corrupted or has an invalid structure. Please try using the \'Repair PDF\' feature to fix the file before proceeding.'; window.stirlingPDF.tryRepairMessage = /*[[#{error.tryRepair}]]*/ 'Try using the Repair PDF feature to fix corrupted files.'; + window.stirlingPDF.currentPage = /*[[${currentPage}]]*/ ''; })();