Compare commits

...

2 commits

Author SHA1 Message Date
xenofem 3b974ed6a3 check upload limits beforehand 2022-05-03 19:21:42 -04:00
xenofem a79e9ae99c fix image paths in css 2022-05-03 19:21:03 -04:00
5 changed files with 40 additions and 17 deletions

View file

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

View file

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

View file

@ -60,7 +60,7 @@ body {
width: 18px;
height: 18px;
background-color: #333;
mask-image: url("images/feather-icons/copy.svg");
mask-image: url("../images/feather-icons/copy.svg");
mask-size: contain;
mask-repeat: no-repeat;
}
@ -108,7 +108,7 @@ td {
.delete_button {
background-color: #888;
mask-image: url("images/feather-icons/x.svg");
mask-image: url("../images/feather-icons/x.svg");
mask-size: contain;
mask-repeat: no-repeat;
mask-position: center;

View file

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

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