2021-05-08 22:46:12 +02:00
|
|
|
// Enable JS-only functionalities and disable nojs ones.
|
|
|
|
Array.prototype.slice.call(document.getElementsByClassName("jsonly")).forEach(e => e.removeAttribute("style"));
|
|
|
|
Array.prototype.slice.call(document.getElementsByClassName("nojs")).forEach(e => e.style.display = "none");
|
|
|
|
document.getElementById('fileinput').setAttribute('multiple','');
|
|
|
|
|
|
|
|
// get form
|
|
|
|
const form = document.getElementById('dropzone');
|
|
|
|
|
2021-05-08 23:16:09 +02:00
|
|
|
function upload(file,exp,maxdl) {
|
2021-05-08 22:46:12 +02:00
|
|
|
// create the XHR
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
// Create list item
|
|
|
|
const list=document.getElementById('links');
|
|
|
|
var entry=document.createElement('li');
|
|
|
|
entry.innerHTML = file.name + '<br /><progress></progress>';
|
|
|
|
list.appendChild(entry);
|
|
|
|
|
|
|
|
// Progress bar
|
|
|
|
xhr.upload.addEventListener('progress', function(e) {
|
|
|
|
entry.innerHTML = file.name + '<br /><progress max="' + e.total + '" value="' + e.loaded +'"></progress>';
|
|
|
|
});
|
|
|
|
|
|
|
|
// Links response
|
|
|
|
xhr.onload = () => {
|
2021-06-06 14:43:27 +02:00
|
|
|
entry.innerHTML = '<a target="_blank" href="' + xhr.responseText + '">' + xhr.responseText + '</a>';
|
2021-05-08 22:46:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// create and send the request
|
|
|
|
xhr.open('PUT', '/' + file.name);
|
2021-05-08 23:16:09 +02:00
|
|
|
// add headers
|
|
|
|
if (exp != "") {
|
|
|
|
xhr.setRequestHeader('Max-Days',exp);
|
|
|
|
}
|
2021-06-06 15:00:36 +02:00
|
|
|
if (maxdl != 0) {
|
2021-05-08 23:16:09 +02:00
|
|
|
xhr.setRequestHeader('Max-Downloads',maxdl);
|
|
|
|
}
|
|
|
|
// send file
|
2021-05-08 22:46:12 +02:00
|
|
|
xhr.send(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add event listener on form
|
|
|
|
form.addEventListener('submit', e => {
|
|
|
|
// disable normal sending
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// get file list
|
|
|
|
const files = document.getElementById('fileinput').files;
|
2021-05-08 23:16:09 +02:00
|
|
|
const exp = document.getElementById('expiration').value;
|
|
|
|
const maxdl = document.getElementById('maxdl').value;
|
2021-05-08 22:46:12 +02:00
|
|
|
|
|
|
|
// upload each file
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
2021-05-08 23:16:09 +02:00
|
|
|
upload(files[i],exp,maxdl);
|
2021-05-08 22:46:12 +02:00
|
|
|
}
|
2021-06-06 15:11:52 +02:00
|
|
|
|
|
|
|
// reset file list
|
|
|
|
document.getElementById('fileinput').value='';
|
2021-05-08 22:46:12 +02:00
|
|
|
});
|