aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/cargohold.js10
-rw-r--r--backend/main.py31
2 files changed, 26 insertions, 15 deletions
diff --git a/assets/cargohold.js b/assets/cargohold.js
index cd6cc34..2ba8cc0 100644
--- a/assets/cargohold.js
+++ b/assets/cargohold.js
@@ -100,9 +100,9 @@ function listing_clear(){
element("dirlisting").innerHTML = "";
}
-function listing_add(name){
- let link = node("a", "listing-entry", name);
- link.href = "file/" + encodeURIComponent(name);
+function listing_add(file){
+ let link = node("a", "listing-entry", file.name);
+ link.href = "file/" + encodeURIComponent(file.name);
element("dirlisting").appendChild(link);
}
@@ -111,8 +111,8 @@ function listing_update(){
let req = new XMLHttpRequest();
req.onload = function(evt){
let data = JSON.parse(req.response);
- for(let i = 0; i < data.length; i++){
- listing_add(data[i]);
+ for(let i = 0; i < data.files.length; i++){
+ listing_add(data.files[i]);
}
};
req.open("GET", "listing");
diff --git a/backend/main.py b/backend/main.py
index 716ca13..592b7a3 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -11,14 +11,13 @@ def playout(filename, content = "text/html"):
def home():
return ["", [('Content-Type','text/html'), ("Location", config.homepage)], "302 Home"]
-def target_filename_internal(session, file):
- target = ""
- if not file:
- file = ""
+def target_filename_internal(session, filename):
+ target = session["path"] + "/"
+ if filename:
+ target += filename
if config.user_subdirs:
- target = session["user"] + "/"
- return target + session["path"] + "/" + file
-
+ target = session["user"] + "/" + target
+ return target
def target_filename(session, file):
return config.fileroot + target_filename_internal(session, file)
@@ -37,11 +36,23 @@ def resolve_alias(alias):
return session
def listing(session):
- target = target_filename(session, None)
- files = os.listdir(target)
- return [json.dumps(files), [('Content-Type','application/json')], "200 OK"]
+ listing = {"total": 0, "files": []}
+ if 'r' not in session["access"]:
+ return ["", [('Content-Type','text/html')], "403 No"]
+
+ directory = target_filename(session, None)
+ files = os.listdir(directory)
+
+ for filename in files:
+ size = os.path.getsize(directory + filename)
+ listing["files"].append({"name": filename, "size": size})
+ listing["total"] += size
+
+ return [json.dumps(listing), [('Content-Type','application/json')], "200 OK"]
def upload(session, post):
+ if 'c' not in session["access"]:
+ return ["", [('Content-Type','text/html')], "403 No"]
if post["file"].filename:
target = target_filename(session, os.path.basename(post["file"].filename))
try: