// 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');
function upload(file,exp,maxdl) {
// create the XHR
const xhr = new XMLHttpRequest();
// Create list item
const list=document.getElementById('links');
var entry=document.createElement('li');
entry.innerHTML = file.name + '
';
list.appendChild(entry);
// Progress bar
xhr.upload.addEventListener('progress', function(e) {
entry.innerHTML = file.name + '
';
});
// Links response
xhr.onload = () => {
entry.innerHTML = '' + xhr.responseText + '';
};
// create and send the request
xhr.open('PUT', '/' + file.name);
// add headers
if (exp != "") {
xhr.setRequestHeader('Max-Days',exp);
}
if (maxdl != 0) {
xhr.setRequestHeader('Max-Downloads',maxdl);
}
// send file
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;
const exp = document.getElementById('expiration').value;
const maxdl = document.getElementById('maxdl').value;
// upload each file
for (let i = 0; i < files.length; i++) {
upload(files[i],exp,maxdl);
}
// reset file list
document.getElementById('fileinput').value='';
});