aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources
diff options
context:
space:
mode:
authorMarvin Borner2019-04-19 22:07:22 +0200
committerMarvin Borner2019-04-19 22:07:22 +0200
commit5523bd7a5e30b09baa6bb3ccd23252d0ebef6000 (patch)
tree9e0ec38ac5f0ac3dc208eb2be0bc0eef24d5a5e0 /src/main/resources
parentfe97c12731193211caf8652a6fd40e02d0d429b4 (diff)
Fixed recursive upload function
Co-authored-by: LarsVomMars <lars@kroenner.eu>
Diffstat (limited to 'src/main/resources')
-rw-r--r--src/main/resources/js/files.js34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/main/resources/js/files.js b/src/main/resources/js/files.js
index 6016ba0..69cdf32 100644
--- a/src/main/resources/js/files.js
+++ b/src/main/resources/js/files.js
@@ -18,10 +18,9 @@ drop.addEventListener('drop', e => {
e.preventDefault();
drop.style.background = "white";
const items = e.dataTransfer.items;
+ const uploadedFiles = [];
for (let i = 0; i < items.length; i++) {
- const request = new XMLHttpRequest();
- const formData = new FormData();
const item = items[i].webkitGetAsEntry();
const file = items[i].getAsFile();
@@ -52,12 +51,18 @@ drop.addEventListener('drop', e => {
} else {
subItem.file(subFile => {
// TODO: Add support for nested directory upload with more than 1 layer - via webkitRelativePath on firefox?
- formData.append("file", subFile);
- console.log(subFile);
- console.log(file);
- if (subFile.webkitRelativePath === "") request.open("POST", `/upload/${path}/${file.name}`);
- else request.open("POST", `/upload/${path}`);
- request.send(formData);
+ 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();
+
+ uploadedFiles.push(`${path}/${file.name}/${subFile.name}`);
+ formData.append("file", subFile);
+ if (subFile.webkitRelativePath === "") request.open("POST", `/upload/${path}/${file.name}`);
+ else request.open("POST", `/upload/${path}`);
+ request.send(formData);
+ }
})
}
};
@@ -65,9 +70,14 @@ drop.addEventListener('drop', e => {
if (item.isDirectory) {
iterateFiles(item);
} else {
- formData.append("file", file);
- request.open("POST", `/upload/${path}`, true);
- request.send(formData);
+ if (!uploadedFiles.includes(`${path}/${file.name}`)) {
+ const formData = new FormData();
+ const request = new XMLHttpRequest();
+
+ formData.append("file", file);
+ request.open("POST", `/upload/${path}`);
+ request.send(formData);
+ }
}
}
@@ -153,7 +163,7 @@ function setListeners() {
const parent = e.target.closest("tr");
const fileName = parent.getAttribute("data-href") || parent.getAttribute("data-path");
if (confirm(`Do you really want to delete: ${fileName}?`)) {
- request.open("POST", `/delete/${path}/${fileName}`);
+ request.open("POST", `/delete/${path}/${fileName}`, true);
request.send();
parent.remove();
} else console.log("File not deleted!")