From 4b6176989ef49b1f0de880f6dc1f48e365df1b58 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 16:22:44 +0200 Subject: [PATCH] cxvxvc --- files/__main__.py | 4 ---- files/helpers/sanitize.py | 4 ++-- files/routes/admin.py | 6 +----- files/routes/static.py | 3 ++- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 301b743c0d..93ea7aca98 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -109,8 +109,4 @@ def after_request(response): response.headers.add("X-Frame-Options", "deny") return response -if cache.get("marsey_count") == None: - with open("marsey_count.json", 'r') as f: - cache.set("marsey_count", loads(f.read())) - from files.routes import * \ No newline at end of file diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 4733686527..d205648f46 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -178,7 +178,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = re.sub('\|\|(.*?)\|\|', r'\1', sanitized) if comment: - marsey_count = cache.get("marsey_count") + with open("marsey_count.json", 'r') as f: marsey_count = loads(f.read()) marseys_used = set() for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized): @@ -260,7 +260,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if comment: for emoji in marseys_used: if emoji in marsey_count: marsey_count[emoji] += 1 - cache.set("marsey_count", marsey_count) + with open('marsey_count.json', 'w') as f: dump(marsey_count, f) return sanitized diff --git a/files/routes/admin.py b/files/routes/admin.py index 5ab825190d..55a48302a6 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -385,9 +385,6 @@ def disable_signups(v): @app.post("/admin/purge_cache") @admin_level_required(3) def purge_cache(v): - with open('marsey_count.json', 'w') as f: dump(cache.get("marsey_count"), f) - cache.clear() - with open("marsey_count.json", 'r') as f: cache.set("marsey_count", loads(f.read())) response = str(requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data='{"purge_everything":true}')) if response == "": return {"message": "Cache purged!"} return {"error": "Failed to purge cache."} @@ -1198,6 +1195,7 @@ def api_unban_comment(c_id, v): @admin_level_required(1) def admin_distinguish_comment(c_id, v): + comment = get_comment(c_id, v=v) if comment.author_id != v.id: abort(403) @@ -1213,9 +1211,7 @@ def admin_distinguish_comment(c_id, v): @app.get("/admin/dump_cache") @admin_level_required(2) def admin_dump_cache(v): - with open('marsey_count.json', 'w') as f: dump(cache.get("marsey_count"), f) cache.clear() - with open("marsey_count.json", 'r') as f: cache.set("marsey_count", loads(f.read())) return {"message": "Internal cache cleared."} diff --git a/files/routes/static.py b/files/routes/static.py index 462ac9521e..2f78698fab 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -17,7 +17,8 @@ def privacy(v): @app.get("/marseys") @auth_required def emojis(v): - marsey_count = cache.get("marsey_count") + with open("marsey_count.json", 'r') as file: + marsey_count = loads(file.read()) marsey_counted = [] for k, val in marseys.items(): marsey_counted.append((k, val, marsey_count[k]))