From f7cce1469cc4b9db7f71cc59170e06d0ac6df72b Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 10 Jun 2022 23:52:32 +0200 Subject: [PATCH] Revert "use redis for site settings instead of a json file" This reverts commit a7b67db555cc5ae8419ae4d452f93bd0d388fb30. --- .gitignore | 3 ++- files/__main__.py | 7 +++---- files/routes/admin.py | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 5061868cf..5b21b7455 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ venv/ .vscode/ .sass-cache/ flask_session/ -.DS_Store \ No newline at end of file +.DS_Store +site_settings.json \ No newline at end of file diff --git a/files/__main__.py b/files/__main__.py index e84393345..da7c2681f 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -56,6 +56,7 @@ app.config['MAIL_USE_TLS'] = True app.config['MAIL_USERNAME'] = environ.get("MAIL_USERNAME", "").strip() app.config['MAIL_PASSWORD'] = environ.get("MAIL_PASSWORD", "").strip() app.config['DESCRIPTION'] = environ.get("DESCRIPTION", "rdrama.net caters to drama in all forms such as: Real life, videos, photos, gossip, rumors, news sites, Reddit, and Beyond™. There isn't drama we won't touch, and we want it all!").strip() +app.config['SETTINGS'] = {} r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) @@ -81,9 +82,6 @@ cache = Cache(app) Compress(app) mail = Mail(app) -if not cache.get(f'{app.config["SERVER_NAME"]}_settings'): - cache.set(f'{app.config["SERVER_NAME"]}_settings', {"Bots": True, "Fart mode": False, "Read-only mode": False, "Signups": True}) - @app.before_request def before_request(): @@ -92,7 +90,8 @@ def before_request(): ua = g.agent.lower() - app.config['SETTINGS'] = cache.get(f'{app.config["SERVER_NAME"]}_settings') + with open('site_settings.json', 'r') as f: + app.config['SETTINGS'] = json.load(f) if request.host != app.config["SERVER_NAME"]: return {"error":"Unauthorized host provided."}, 401 if request.headers.get("CF-Worker"): return {"error":"Cloudflare workers are not allowed to access this website."}, 401 diff --git a/files/routes/admin.py b/files/routes/admin.py index 9a4466a84..ac55c4577 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -506,8 +506,9 @@ def admin_git_head(): @admin_level_required(3) def change_settings(v, setting): site_settings = app.config['SETTINGS'] - site_settings[setting] = not site_settings[setting] - cache.set(f'{SITE}_settings', site_settings) + site_settings[setting] = not site_settings[setting] + with open("site_settings.json", "w") as f: + json.dump(site_settings, f) if site_settings[setting]: word = 'enable' else: word = 'disable'