aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/js
diff options
context:
space:
mode:
authorMarvin Borner2019-05-16 18:07:53 +0200
committerMarvin Borner2019-05-16 18:07:53 +0200
commit5cbb9d1ffe6ad4b7d89c0b189a7821d1005bbdda (patch)
treedcc1c61837d92e4e1224b79295075d43d1989b0e /src/main/resources/js
parentf98205bb8215de29aacf5bc6591734af2d4c4d12 (diff)
Fixed many issues with directory uploading and sharing
Co-authored-by: LarsVomMars <lars@kroenner.eu>
Diffstat (limited to 'src/main/resources/js')
-rw-r--r--src/main/resources/js/files.js28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/main/resources/js/files.js b/src/main/resources/js/files.js
index 00015c4..9c8c135 100644
--- a/src/main/resources/js/files.js
+++ b/src/main/resources/js/files.js
@@ -43,15 +43,34 @@ drop.addEventListener('drop', e => {
setListeners();
iterateFiles(item, files => {
+ const progress = document.getElementById("progress");
const request = new XMLHttpRequest();
const formData = new FormData();
for (const file of files)
formData.append('file', file);
+ request.upload.onprogress = e => {
+ if (e.lengthComputable) {
+ progress.style.display = "block";
+ progress.innerText = `Uploading ${files.length} file(s): ${(e.loaded / e.total * 100).toFixed(2)}%`;
+ }
+ };
+
+ request.onreadystatechange = () => {
+ if (request.readyState === 4) {
+ if (request.status === 200) {
+ progress.innerText = "Finished uploading!";
+ setTimeout(() => progress.style.display = "none", 3000)
+ } else {
+ progress.style.color = "red";
+ progress.innerText = "An error occurred :(";
+ }
+ }
+ };
+
request.open('POST', `/upload/${path}`.clean(), true);
request.send(formData);
-
});
}
@@ -212,16 +231,14 @@ setListeners();
/**
* Iterates over files and directories
+ * TODO: Add empty directory upload support
* @param item
* @param callback
*/
-// TODO: Add empty directory upload support
-const files = [];
-
function iterateFiles(item, callback) {
+ const files = [];
console.log(item);
(function iterate(subItem) {
- console.log(subItem);
if (subItem.isDirectory) {
const directoryReader = subItem.createReader();
directoryReader.readEntries(entries => {
@@ -233,7 +250,6 @@ function iterateFiles(item, callback) {
} else
subItem.file(file => {
const newName = subItem.fullPath.charAt(0) === '/' ? subItem.fullPath.substr(1) : subItem.fullPath;
- console.log(newName);
files.push(new File([file], newName, {
lastModified: file.lastModified,
lastModifiedDate: file.lastModifiedDate,