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.
This commit is contained in:
io mintz 2020-11-13 12:46:33 +00:00
parent a52127f0c3
commit 51d51d4c00
3 changed files with 10 additions and 1 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
__pycache__/ __pycache__/
.py[cod] /fhost.cfg

View file

@ -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 Otherwise, Flask will serve the file with chunked encoding, which sucks and
should be avoided at all costs. 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 To make files expire, simply create a cronjob that runs ``cleanup.py`` every
now and then. now and then.

View file

@ -68,6 +68,8 @@ app.config["FHOST_UPLOAD_BLACKLIST"] = "tornodes.txt"
app.config["NSFW_DETECT"] = False app.config["NSFW_DETECT"] = False
app.config["NSFW_THRESHOLD"] = 0.608 app.config["NSFW_THRESHOLD"] = 0.608
app.config.from_pyfile("fhost.cfg", silent=True)
if app.config["NSFW_DETECT"]: if app.config["NSFW_DETECT"]:
from nsfw_detect import NSFWDetector from nsfw_detect import NSFWDetector
nsfw = NSFWDetector() nsfw = NSFWDetector()