aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--loggedin.js27
-rw-r--r--php/readdir.php3
2 files changed, 28 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("/");
diff --git a/php/readdir.php b/php/readdir.php
index e69de29..b6a1916 100644
--- a/php/readdir.php
+++ b/php/readdir.php
@@ -0,0 +1,3 @@
+<?php
+echo '[ { "name": "file1.txt", "mimetype": "text/plain", "is_directory": false }, { "name": "file2.pdf", "mimetype": "application/pdf", "is_directory": false }, { "name": "dir", "mimetype": "", "is_directory": true } ] ';
+?>