aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2022-04-23 14:01:01 +0200
committercbdev <cb@cbcdn.com>2022-04-23 14:01:01 +0200
commitcc15eb40f61413c65d3c9872376eec73727a8969 (patch)
treea4cbb1a80e835eb4f87281ac3c3ea19c3f944158
parent75ddfdb31df5e176bb9eb6e91e1545fced54737e (diff)
downloadcargohold-cc15eb40f61413c65d3c9872376eec73727a8969.tar.gz
cargohold-cc15eb40f61413c65d3c9872376eec73727a8969.tar.bz2
cargohold-cc15eb40f61413c65d3c9872376eec73727a8969.zip
Sort listing before playout
-rw-r--r--README.md17
-rw-r--r--backend/main.py9
2 files changed, 21 insertions, 5 deletions
diff --git a/README.md b/README.md
index dbbdc6f..9cbd7d1 100644
--- a/README.md
+++ b/README.md
@@ -6,10 +6,25 @@ that lets them download or view the files you want them to have.
## Installation
-TBD
+* Install nginx and uwsgi
+* Create a directory where cargohold will store the uploaded files
+* Set the directory's owner to the user you want uwsgi to run the application under
+* Edit `backend/config.py` to match your setup
+* Edit `configs/nginx.config` to match your setup
+ * Note that the `client_max_body_size` will limit the maximum size of a single uploaded file
+* Install `configs/nginx.config` to `/etc/nginx/sites-enabled`
+* Edit `configs/uwsgi.ini` to match your setup
+ * Note that the `limit-post` option will limit the maximum size of a single uploaded file
+* Install `configs/uwsgi.ini` to `/etc/uwsgi/apps-enabled/cargohold.ini`
+
+TBD: Extend this.
## Usage
TBD
## Interface
+
+cargohold integrates somewhat tightly with nginx using the X-Accel-Redirect mechanism.
+Other httpds may provide a similar mechanism, which will need to be called out to in the
+`playout()` routine in `main.py`.
diff --git a/backend/main.py b/backend/main.py
index 76aca81..8af66ca 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -5,8 +5,8 @@ import os
import sqlite3
import mimetypes
-def playout(filename, content = "application/octet-stream"):
- return ["", [('Content-Type', content), ("X-Accel-Redirect", filename)], None]
+def playout(filename, content = "text/html"):
+ return ["", [('Content-Type', content if content else "application/octet-stream"), ("X-Accel-Redirect", filename)], None]
def home():
return ["", [('Content-Type','text/html'), ("Location", config.homepage)], "302 Home"]
@@ -38,9 +38,10 @@ def resolve_alias(alias):
def listing(session):
listing = {"total": 0, "files": [], "access": session["access"], "display": session["display"]}
+ # TODO make sorting configurable
if 'r' in session["access"]:
directory = target_filename(session, None)
- files = os.listdir(directory)
+ files = sorted(os.listdir(directory))
for filename in files:
if os.path.isfile(directory + filename):
@@ -96,7 +97,7 @@ def route(path, env, session, post):
if len(path) > 1 and path[1] == "preview" and session["display"] == "gallery":
return playout("/data/" + target_filename_internal(session, "preview/" + path[2]), mimetypes.guess_type(path[2])[0])
- return playout("/interface/listing.htm", "text/html")
+ return playout("/interface/listing.htm")
def handle_request(env, response):
path = env.get('PATH_INFO', '').lstrip('/').split('/')