check upload limits beforehand
This commit is contained in:
parent
a79e9ae99c
commit
3b974ed6a3
|
@ -139,7 +139,7 @@ struct UploadManifest {
|
|||
enum ServerMessage {
|
||||
Ready { code: String },
|
||||
TooBig { max_size: u64 },
|
||||
TooLong { max_days: u16 },
|
||||
TooLong { max_lifetime: u16 },
|
||||
IncorrectPassword,
|
||||
Error { details: String },
|
||||
}
|
||||
|
@ -150,8 +150,8 @@ impl From<&Error> for ServerMessage {
|
|||
Error::TooBig(max_size) => ServerMessage::TooBig {
|
||||
max_size: *max_size,
|
||||
},
|
||||
Error::TooLong(max_days) => ServerMessage::TooLong {
|
||||
max_days: *max_days,
|
||||
Error::TooLong(max_lifetime) => ServerMessage::TooLong {
|
||||
max_lifetime: *max_lifetime,
|
||||
},
|
||||
Error::IncorrectPassword => ServerMessage::IncorrectPassword,
|
||||
_ => ServerMessage::Error {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* List of classes the body can have:
|
||||
*
|
||||
* landing: haven't entered upload password yet
|
||||
* uploads_closed: uploading is currently unavailable
|
||||
* no_files: no files are selected
|
||||
* selecting: upload hasn't started yet
|
||||
* uploading: upload is in progress
|
||||
|
@ -15,7 +16,11 @@ body.landing .section_heading { display: revert; }
|
|||
#download { display: none; }
|
||||
body.landing #download { display: revert; }
|
||||
|
||||
#uploads_closed_notice { display: none; }
|
||||
body.uploads_closed #uploads_closed_notice { display: revert; }
|
||||
|
||||
body.noscript #upload { display: none; }
|
||||
body.uploads_closed #upload { display: none; }
|
||||
|
||||
#message { display: none; }
|
||||
body.completed #message {
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
</form>
|
||||
</div>
|
||||
<noscript>Javascript is required to upload files :(</noscript>
|
||||
<div id="uploads_closed_notice" class="section">
|
||||
<h4>Uploading is currently closed.</h4>
|
||||
</div>
|
||||
<div id="upload" class="section">
|
||||
<h3 class="section_heading">Upload</h3>
|
||||
<div id="message"></div>
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue