diff --git a/files/__main__.py b/files/__main__.py index effabd220..062b0ff56 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -17,6 +17,7 @@ import redis import time from sys import stdout import faulthandler +import atexit app = Flask(__name__, template_folder='templates') app.wsgi_app = ProxyFix(app.wsgi_app, x_for=3) @@ -84,6 +85,8 @@ mail = Mail(app) @app.before_request def before_request(): + print(request.access_route[0]) + print(request.remote_addr) if request.method.lower() != "get" and app.config["READ_ONLY"]: return {"error":f"{app.config['SITE_NAME']} is currently in read-only mode."}, 500 @@ -109,4 +112,13 @@ def after_request(response): response.headers.add("X-Frame-Options", "deny") return response -from files.routes import * \ No newline at end of file +from files.routes import * + +def close_running_threads(): + with open("marsey_count.json", 'r') as f: marsey_file = loads(f.read()) + print(marsey_count['marseylove']) + if marsey_file != marsey_count: + with open('marsey_count.json', 'w') as f: dump(marsey_count, f) + print("Marsey count saved!") + stdout.flush() +atexit.register(close_running_threads) diff --git a/files/helpers/const.py b/files/helpers/const.py index 8f6abf28c..7af17ba08 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -797,3 +797,10 @@ NOTIFIED_USERS = { num_banners = len(listdir('files/assets/images/Drama/banners')) + 1 num_sidebar = len(listdir('files/assets/images/Drama/sidebar')) + 1 + + +with open("marsey_count.json", 'r') as f: marsey_count = loads(f.read()) +marsey_counted = [] +for k, val in marseys.items(): + marsey_counted.append((k, val, marsey_count[k])) +marsey_counted = sorted(marsey_counted, key=lambda x: x[2], reverse=True) \ No newline at end of file diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index d205648f4..228d49099 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -178,7 +178,6 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = re.sub('\|\|(.*?)\|\|', r'\1', sanitized) if comment: - 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 +259,6 @@ 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 - with open('marsey_count.json', 'w') as f: dump(marsey_count, f) return sanitized diff --git a/files/routes/comments.py b/files/routes/comments.py index a771710bb..e2bb0e51b 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -481,7 +481,7 @@ def api_comment(v): 'body': notifbody, }, 'data': { - 'url': f'comment/{c.id}?context=9&read=true#context', + 'url': f'/comment/{c.id}?context=9&read=true#context', } } }, diff --git a/files/routes/static.py b/files/routes/static.py index 2f78698fa..02ba09982 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -17,12 +17,6 @@ def privacy(v): @app.get("/marseys") @auth_required def emojis(v): - 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])) - marsey_counted = sorted(marsey_counted, key=lambda x: x[2], reverse=True) return render_template("marseys.html", v=v, marseys=marsey_counted) @app.get("/terms") diff --git a/files/routes/users.py b/files/routes/users.py index e24dd1809..75fa36059 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -503,7 +503,7 @@ def message2(v, username): 'body': notifbody, }, 'data': { - 'url': 'notifications?messages=true', + 'url': '/notifications?messages=true', } } }, @@ -570,7 +570,7 @@ def messagereply(v): 'body': notifbody, }, 'data': { - 'url': 'notifications?messages=true', + 'url': '/notifications?messages=true', } } }, diff --git a/requirements.txt b/requirements.txt index 2b9065681..0a46c4b26 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ bleach Flask Flask-Caching Flask-Compress -Flask-Limiter==1.1.0 +Flask-Limiter Flask-Mail gevent greenlet