fix(repair): suppress corrupted PDF error/warning banner on repair page (#4434)

# 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

<!--
Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)
-->

---

## 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 <bszucs1209@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Balázs Szücs 2025-10-11 19:23:44 +02:00 committed by GitHub
parent 60c7ba40a6
commit fda1d6bc73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 9 deletions

View File

@ -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);
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.');
}

View File

@ -249,10 +249,15 @@
(error.message && error.message.includes('Invalid PDF structure'))) {
// Handle corrupted PDF files
console.log(`Corrupted PDF detected: ${file.name}`, error);
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);

View File

@ -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}]]*/ '';
})();
</script>
<script type="module" th:src="@{'/pdfjs-legacy/pdf.mjs'}"></script>