Enforce the limit on uploading

This commit is contained in:
Pedro Fonseca 2025-04-11 11:09:27 +01:00
parent 8110fef364
commit 187de811ee
2 changed files with 20 additions and 0 deletions

View File

@ -43,6 +43,14 @@
firstErrorOccurred = false;
const url = this.action;
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}" is too large. Maximum allowed size is ${window.stirlingPDF.uploadLimitReadable}.`);
return;
}
}
const formData = new FormData(this);
const submitButton = document.getElementById('submitBtn');
const showGameBtn = document.getElementById('show-game-btn');

View File

@ -179,6 +179,18 @@ function setupFileInput(chooser) {
await checkZipFile();
const uploadLimit = window.stirlingPDF?.uploadLimit ?? 0;
if (uploadLimit > 0) {
const oversizedFile = allFiles.find(f => f.size > uploadLimit);
if (oversizedFile) {
alert(`"${oversizedFile.name}" is too large. Maximum allowed size is ${window.stirlingPDF.uploadLimitReadable}.`);
allFiles = [];
input.value = '';
inputContainer.querySelector('#fileInputText').innerHTML = originalText;
return;
}
}
allFiles = await Promise.all(
allFiles.map(async (file) => {
let decryptedFile = file;