From 51d51d4c00d9a5b66276a670b59308b5351a5e82 Mon Sep 17 00:00:00 2001 From: io mintz Date: Fri, 13 Nov 2020 12:46:33 +0000 Subject: [PATCH] fhost: allow configuration at runtime This reads configuration from a file called `fhost.cfg` if it exists, allowing users to configure the server without having to maintain a fork. --- .gitignore | 2 +- README.rst | 7 +++++++ fhost.py | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 64799da..7e0cbb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ __pycache__/ -.py[cod] +/fhost.cfg diff --git a/README.rst b/README.rst index cf2ac7d..cee9b89 100644 --- a/README.rst +++ b/README.rst @@ -19,6 +19,13 @@ For all other servers, set ``FHOST_USE_X_ACCEL_REDIRECT`` to ``False`` and Otherwise, Flask will serve the file with chunked encoding, which sucks and should be avoided at all costs. +You can configure these parameters by creating a file called ``fhost.cfg`` +and placing normal python assignment statements in it. For example:: + + FHOST_USE_ACCEL_REDIRECT = False + FHOST_USE_X_SENDFILE = True + MAX_URL_LENGTH = 4096 + To make files expire, simply create a cronjob that runs ``cleanup.py`` every now and then. diff --git a/fhost.py b/fhost.py index 2814a96..8ec32d7 100755 --- a/fhost.py +++ b/fhost.py @@ -68,6 +68,8 @@ app.config["FHOST_UPLOAD_BLACKLIST"] = "tornodes.txt" app.config["NSFW_DETECT"] = False app.config["NSFW_THRESHOLD"] = 0.608 +app.config.from_pyfile("fhost.cfg", silent=True) + if app.config["NSFW_DETECT"]: from nsfw_detect import NSFWDetector nsfw = NSFWDetector()