Allow for non-offending files to still be uploaded, downloader.js file version

This commit is contained in:
Pedro Fonseca 2025-04-12 01:25:13 +01:00
parent 7dc707c185
commit a4a84ba285
2 changed files with 10 additions and 7 deletions

View File

@ -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);

View File

@ -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;