diff options
author | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-12 14:21:12 +0200 |
---|---|---|
committer | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-12 14:21:12 +0200 |
commit | 1de4d8dea14a9641206cd91613388ee5f228bae5 (patch) | |
tree | 368f1ed07d8f9e9ed0d54d2451463c4f6f027fe8 /loggedin.js | |
parent | 10d7e23ca54ca0003e548922d1202f39c841a0db (diff) | |
download | fileup-1de4d8dea14a9641206cd91613388ee5f228bae5.tar.gz |
front end for readdir
Diffstat (limited to 'loggedin.js')
-rw-r--r-- | loggedin.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/loggedin.js b/loggedin.js index 436719f..d774e16 100644 --- a/loggedin.js +++ b/loggedin.js @@ -8,7 +8,9 @@ const current_directory = document.getElementById("current_directory"); the_file.onchange = on_file_added; -const files = []; +var files = []; + +const pwd = "/"; const pending_uploads = []; @@ -44,7 +46,26 @@ function on_file_added(_e) { } -function add_file_visuals(name, pending) { +function load_dir(pwd) { + var data = new FormData(); + data.append('path', '/'); + + var xhr = new XMLHttpRequest(); + xhr.open('POST', '/php/readdir.php', true); + xhr.onload = function () { + for (const f of files) + f[1].remove(); + files = []; + + var json = JSON.parse(this.responseText); + for (const f of json) { + add_file_visuals(f.name, f.mimetype); + } + }; + xhr.send(data); +} + +function add_file_visuals(name, mimetype) { var fileDiv = document.createElement('div'); var img = document.createElement('img'); @@ -68,3 +89,5 @@ function add_file_visuals(name, pending) { function begin_upload() { the_file.click(); } + +load_dir("/"); |