aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/js
diff options
context:
space:
mode:
authorMarvin Borner2019-04-19 23:38:36 +0200
committerMarvin Borner2019-04-19 23:38:36 +0200
commit9fe9795c996a6e37e894f7e42ba8761320c47798 (patch)
tree2b3bc8b325ff0e3ea31a555e7bdbfba933194c5f /src/main/resources/js
parent5523bd7a5e30b09baa6bb3ccd23252d0ebef6000 (diff)
Increased stability and security
Co-authored-by: LarsVomMars <lars@kroenner.eu>
Diffstat (limited to 'src/main/resources/js')
-rw-r--r--src/main/resources/js/files.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main/resources/js/files.js b/src/main/resources/js/files.js
index 69cdf32..3346a31 100644
--- a/src/main/resources/js/files.js
+++ b/src/main/resources/js/files.js
@@ -51,12 +51,16 @@ drop.addEventListener('drop', e => {
} else {
subItem.file(subFile => {
// TODO: Add support for nested directory upload with more than 1 layer - via webkitRelativePath on firefox?
- console.log(uploadedFiles);
- console.log(`${path}/${file.name}/${subFile.name}`);
if (!uploadedFiles.includes(`${path}/${file.name}/${subFile.name}`)) {
const formData = new FormData();
const request = new XMLHttpRequest();
+ request.upload.onprogress = e => {
+ if (e.lengthComputable) {
+ console.log(`${subFile.name}: ${e.loaded / e.total * 100}%`)
+ }
+ };
+
uploadedFiles.push(`${path}/${file.name}/${subFile.name}`);
formData.append("file", subFile);
if (subFile.webkitRelativePath === "") request.open("POST", `/upload/${path}/${file.name}`);
@@ -74,6 +78,12 @@ drop.addEventListener('drop', e => {
const formData = new FormData();
const request = new XMLHttpRequest();
+ request.upload.onprogress = e => {
+ if (e.lengthComputable) {
+ console.log(`${file.name}: ${e.loaded / e.total * 100}%`)
+ }
+ };
+
formData.append("file", file);
request.open("POST", `/upload/${path}`);
request.send(formData);
@@ -114,7 +124,7 @@ function setListeners() {
element.addEventListener("click", () => {
if (images.indexOf(extension) === -1 && videos.indexOf(extension) === -1 && audio.indexOf(extension) === -1)
- window.location = filename; // download binary files
+ window.location = `/files/${path}/${filename}`; // download binary files
});
});
@@ -151,7 +161,7 @@ function setListeners() {
// normal files
document.querySelectorAll("[data-href]").forEach(element => {
element.addEventListener("click", () => {
- window.location = element.getAttribute("data-href");
+ window.location = `/files${path}/${element.getAttribute("data-href")}`;
})
});