check upload limits beforehand

This commit is contained in:
xenofem 2022-05-03 19:21:42 -04:00
parent a79e9ae99c
commit 3b974ed6a3
4 changed files with 38 additions and 15 deletions

View file

@ -23,7 +23,7 @@ let progress;
let progressBar;
document.addEventListener('DOMContentLoaded', () => {
document.body.className = "landing";
document.body.className = 'landing';
messageBox = document.getElementById('message');
fileInput = document.getElementById('file_input');
@ -34,6 +34,17 @@ document.addEventListener('DOMContentLoaded', () => {
progress = document.getElementById('progress');
progressBar = document.getElementById('progress_bar');
fetch('/upload/limits.json')
.then((res) => res.json())
.then((limits) => {
if (limits.open === false) {
document.body.className = 'uploads_closed landing';
return;
}
maxSize = limits.max_size;
updateMaxLifetime(limits.max_lifetime);
});
const uploadPasswordInput = document.getElementById('upload_password');
const uploadPasswordForm = document.getElementById('upload_password_form');
uploadPasswordForm.addEventListener('submit', (e) => {
@ -193,17 +204,8 @@ function handleMessage(msg) {
maxSize = reply.max_size;
updateFiles();
} else if (reply.type === 'too_long') {
let options = Array.from(lifetimeInput.options);
options.reverse();
for (const option of options) {
if (option.value > reply.max_days) {
option.disabled = true;
} else {
option.selected = true;
break;
}
}
displayError(`The maximum retention time for uploads is ${reply.max_days} days`);
updateMaxLifetime(reply.max_lifetime);
displayError(`The maximum retention time for uploads is ${reply.max_lifetime} days`);
} else if (reply.type === 'incorrect_password') {
messageBox.textContent = ('Incorrect password');
document.body.className = 'error landing';
@ -221,6 +223,19 @@ function handleMessage(msg) {
}
}
function updateMaxLifetime(lifetime) {
let options = Array.from(lifetimeInput.options);
options.reverse();
for (const option of options) {
if (option.value > lifetime) {
option.disabled = true;
} else {
option.selected = true;
break;
}
}
}
function sendData() {
if (fileIndex >= files.length) {
finishSending();