check upload limits beforehand
This commit is contained in:
parent
a79e9ae99c
commit
3b974ed6a3
|
@ -139,7 +139,7 @@ struct UploadManifest {
|
||||||
enum ServerMessage {
|
enum ServerMessage {
|
||||||
Ready { code: String },
|
Ready { code: String },
|
||||||
TooBig { max_size: u64 },
|
TooBig { max_size: u64 },
|
||||||
TooLong { max_days: u16 },
|
TooLong { max_lifetime: u16 },
|
||||||
IncorrectPassword,
|
IncorrectPassword,
|
||||||
Error { details: String },
|
Error { details: String },
|
||||||
}
|
}
|
||||||
|
@ -150,8 +150,8 @@ impl From<&Error> for ServerMessage {
|
||||||
Error::TooBig(max_size) => ServerMessage::TooBig {
|
Error::TooBig(max_size) => ServerMessage::TooBig {
|
||||||
max_size: *max_size,
|
max_size: *max_size,
|
||||||
},
|
},
|
||||||
Error::TooLong(max_days) => ServerMessage::TooLong {
|
Error::TooLong(max_lifetime) => ServerMessage::TooLong {
|
||||||
max_days: *max_days,
|
max_lifetime: *max_lifetime,
|
||||||
},
|
},
|
||||||
Error::IncorrectPassword => ServerMessage::IncorrectPassword,
|
Error::IncorrectPassword => ServerMessage::IncorrectPassword,
|
||||||
_ => ServerMessage::Error {
|
_ => ServerMessage::Error {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* List of classes the body can have:
|
* List of classes the body can have:
|
||||||
*
|
*
|
||||||
* landing: haven't entered upload password yet
|
* landing: haven't entered upload password yet
|
||||||
|
* uploads_closed: uploading is currently unavailable
|
||||||
* no_files: no files are selected
|
* no_files: no files are selected
|
||||||
* selecting: upload hasn't started yet
|
* selecting: upload hasn't started yet
|
||||||
* uploading: upload is in progress
|
* uploading: upload is in progress
|
||||||
|
@ -15,7 +16,11 @@ body.landing .section_heading { display: revert; }
|
||||||
#download { display: none; }
|
#download { display: none; }
|
||||||
body.landing #download { display: revert; }
|
body.landing #download { display: revert; }
|
||||||
|
|
||||||
|
#uploads_closed_notice { display: none; }
|
||||||
|
body.uploads_closed #uploads_closed_notice { display: revert; }
|
||||||
|
|
||||||
body.noscript #upload { display: none; }
|
body.noscript #upload { display: none; }
|
||||||
|
body.uploads_closed #upload { display: none; }
|
||||||
|
|
||||||
#message { display: none; }
|
#message { display: none; }
|
||||||
body.completed #message {
|
body.completed #message {
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<noscript>Javascript is required to upload files :(</noscript>
|
<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">
|
<div id="upload" class="section">
|
||||||
<h3 class="section_heading">Upload</h3>
|
<h3 class="section_heading">Upload</h3>
|
||||||
<div id="message"></div>
|
<div id="message"></div>
|
||||||
|
|
|
@ -23,7 +23,7 @@ let progress;
|
||||||
let progressBar;
|
let progressBar;
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
document.body.className = "landing";
|
document.body.className = 'landing';
|
||||||
|
|
||||||
messageBox = document.getElementById('message');
|
messageBox = document.getElementById('message');
|
||||||
fileInput = document.getElementById('file_input');
|
fileInput = document.getElementById('file_input');
|
||||||
|
@ -34,6 +34,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
progress = document.getElementById('progress');
|
progress = document.getElementById('progress');
|
||||||
progressBar = document.getElementById('progress_bar');
|
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 uploadPasswordInput = document.getElementById('upload_password');
|
||||||
const uploadPasswordForm = document.getElementById('upload_password_form');
|
const uploadPasswordForm = document.getElementById('upload_password_form');
|
||||||
uploadPasswordForm.addEventListener('submit', (e) => {
|
uploadPasswordForm.addEventListener('submit', (e) => {
|
||||||
|
@ -193,17 +204,8 @@ function handleMessage(msg) {
|
||||||
maxSize = reply.max_size;
|
maxSize = reply.max_size;
|
||||||
updateFiles();
|
updateFiles();
|
||||||
} else if (reply.type === 'too_long') {
|
} else if (reply.type === 'too_long') {
|
||||||
let options = Array.from(lifetimeInput.options);
|
updateMaxLifetime(reply.max_lifetime);
|
||||||
options.reverse();
|
displayError(`The maximum retention time for uploads is ${reply.max_lifetime} days`);
|
||||||
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`);
|
|
||||||
} else if (reply.type === 'incorrect_password') {
|
} else if (reply.type === 'incorrect_password') {
|
||||||
messageBox.textContent = ('Incorrect password');
|
messageBox.textContent = ('Incorrect password');
|
||||||
document.body.className = 'error landing';
|
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() {
|
function sendData() {
|
||||||
if (fileIndex >= files.length) {
|
if (fileIndex >= files.length) {
|
||||||
finishSending();
|
finishSending();
|
||||||
|
|
Loading…
Reference in a new issue