From 1de4d8dea14a9641206cd91613388ee5f228bae5 Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Fri, 12 Feb 2021 14:21:12 +0200 Subject: front end for readdir --- loggedin.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'loggedin.js') 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("/"); -- cgit v1.2.3