From a4a84ba285ae5ed7d16231b169cd85a6de30e6db Mon Sep 17 00:00:00 2001 From: Pedro Fonseca Date: Sat, 12 Apr 2025 01:25:13 +0100 Subject: [PATCH] Allow for non-offending files to still be uploaded, downloader.js file version --- src/main/resources/static/js/downloader.js | 14 ++++++++++---- src/main/resources/static/js/fileInput.js | 3 --- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/resources/static/js/downloader.js b/src/main/resources/static/js/downloader.js index e8e0b4c18..3b325b597 100644 --- a/src/main/resources/static/js/downloader.js +++ b/src/main/resources/static/js/downloader.js @@ -45,10 +45,16 @@ let files = $('#fileInput-input')[0].files; const uploadLimit = window.stirlingPDF?.uploadLimit ?? 0; if (uploadLimit > 0) { - const oversizedFile = Array.from(files).find(f => f.size > uploadLimit); - if (oversizedFile) { - alert(`"${oversizedFile.name}" ${window.stirlingPDF.uploadLimitExceeded} ${window.stirlingPDF.uploadLimitReadable}.`); - return; + const oversizedFiles = Array.from(files).filter(f => f.size > uploadLimit); + if (oversizedFiles.length > 0) { + const names = oversizedFiles.map(f => `"${f.name}"`).join(', '); + if (names.length === 1) { + alert(`${names} ${window.stirlingPDF.uploadLimitExceededSingular} ${window.stirlingPDF.uploadLimitReadable}.`); + } else { + alert(`${names} ${window.stirlingPDF.uploadLimitExceededPlural} ${window.stirlingPDF.uploadLimitReadable}.`); + } + files = Array.from(files).filter(f => f.size <= uploadLimit); + if (files.length === 0) return; } } const formData = new FormData(this); diff --git a/src/main/resources/static/js/fileInput.js b/src/main/resources/static/js/fileInput.js index 0773389c8..9f05fe13d 100644 --- a/src/main/resources/static/js/fileInput.js +++ b/src/main/resources/static/js/fileInput.js @@ -184,15 +184,12 @@ function setupFileInput(chooser) { const oversizedFiles = allFiles.filter(f => f.size > uploadLimit); if (oversizedFiles.length > 0) { const names = oversizedFiles.map(f => `"${f.name}"`).join(', '); - if (names.length === 1) { alert(`${names} ${window.stirlingPDF.uploadLimitExceededSingular} ${window.stirlingPDF.uploadLimitReadable}.`); } else { alert(`${names} ${window.stirlingPDF.uploadLimitExceededPlural} ${window.stirlingPDF.uploadLimitReadable}.`); } - allFiles = allFiles.filter(f => f.size <= uploadLimit); - const dataTransfer = new DataTransfer(); allFiles.forEach(f => dataTransfer.items.add(f)); input.files = dataTransfer.files;