From 3f0ef520fc163fe07d0e8cd555dcab75a350d7e2 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 14 Dec 2021 23:32:58 +0200 Subject: [PATCH] sdfsdf --- files/__main__.py | 2 +- files/helpers/sanitize.py | 10 +++++----- files/routes/admin.py | 12 ++++++------ files/routes/login.py | 4 ++-- files/routes/static.py | 18 ++++++++++++------ files/templates/{marseys.html => emojis.html} | 8 ++++---- 6 files changed, 30 insertions(+), 24 deletions(-) rename files/templates/{marseys.html => emojis.html} (56%) diff --git a/files/__main__.py b/files/__main__.py index 4fcb842e6..cf27ec39c 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -16,7 +16,7 @@ import gevent from werkzeug.middleware.proxy_fix import ProxyFix import redis -app = Flask(__name__, template_folder='./templates') +app = Flask(__name__, template_folder='templates') app.wsgi_app = ProxyFix(app.wsgi_app, x_for=3) app.url_map.strict_slashes = False app.jinja_env.cache = {} diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 59cdfed8c..dd391d48c 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -182,7 +182,7 @@ def sanitize(sanitized, noimages=False): classes = 'height=60 class="emoji" ' remoji = emoji - if path.isfile(f'./files/assets/images/emojis/{remoji}.webp'): + if path.isfile(f'files/assets/images/emojis/{remoji}.webp'): new = re.sub(f'(?', new, flags=re.I) sanitized = sanitized.replace(old, new) @@ -192,10 +192,10 @@ def sanitize(sanitized, noimages=False): emoji = i.group(1).lower() if emoji.startswith("!"): emoji = emoji[1:] - if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): + if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): sanitized = re.sub(f'(?', sanitized, flags=re.I) - elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): + elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): sanitized = re.sub(f'(?', sanitized, flags=re.I) sanitized = sanitized.replace("https://www.", "https://").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").replace("https://open.spotify.com/", "https://open.spotify.com/embed/").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=").replace("https://mobile.twitter", "https://twitter").replace("https://m.facebook", "https://facebook").replace("https://m.wikipedia", "https://wikipedia").replace("https://m.youtube", "https://youtube") @@ -239,10 +239,10 @@ def filter_emojis_only(title): if emoji.startswith("!"): emoji = emoji[1:] - if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): + if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): title = re.sub(f'(?', title, flags=re.I) - elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): + elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): title = re.sub(f'(?', title, flags=re.I) if len(title) > 1500: abort(400) diff --git a/files/routes/admin.py b/files/routes/admin.py index 4c4c2050f..cafa8d9ce 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -204,7 +204,7 @@ def monthly(v): def get_rules(v): try: - with open(f'./rules_{SITE_NAME}.html', 'r') as f: rules = f.read() + with open(f'rules_{SITE_NAME}.html', 'r') as f: rules = f.read() except Exception: rules = None @@ -219,9 +219,9 @@ def post_rules(v): text = request.values.get('rules', '').strip() - with open(f'./rules_{SITE_NAME}.html', 'w+') as f: f.write(text) + with open(f'rules_{SITE_NAME}.html', 'w+') as f: f.write(text) - with open(f'./rules_{SITE_NAME}.html', 'r') as f: rules = f.read() + with open(f'rules_{SITE_NAME}.html', 'r') as f: rules = f.read() ma = ModAction( kind="change_rules", @@ -317,7 +317,7 @@ def reported_comments(v): @app.get("/admin") @admin_level_required(2) def admin_home(v): - with open('./disablesignups', 'r') as f: + with open('disablesignups', 'r') as f: x = f.read() return render_template("admin/admin_home.html", v=v, x=x) @@ -325,9 +325,9 @@ def admin_home(v): @admin_level_required(2) @validate_formkey def disablesignups(v): - with open('./disablesignups', 'r') as f: content = f.read() + with open('disablesignups', 'r') as f: content = f.read() - with open('./disablesignups', 'w') as f: + with open('disablesignups', 'w') as f: if content == "yes": f.write("no") return {"message": "Signups enabed!"} diff --git a/files/routes/login.py b/files/routes/login.py index 547381366..3a7bdf41a 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -169,7 +169,7 @@ def logout(v): @app.get("/signup") @auth_desired def sign_up_get(v): - with open('./disablesignups', 'r') as f: + with open('disablesignups', 'r') as f: if f.read() == "yes": return "New account registration is currently closed. Please come back later.", 403 if v: return redirect("/") @@ -217,7 +217,7 @@ def sign_up_get(v): @limiter.limit("5/day") @auth_desired def sign_up_post(v): - with open('./disablesignups', 'r') as f: + with open('disablesignups', 'r') as f: if f.read() == "yes": return "New account registration is currently closed. Please come back later.", 403 if v: abort(403) diff --git a/files/routes/static.py b/files/routes/static.py index 71d9db856..754b3f833 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -12,17 +12,23 @@ from files.classes.mod_logs import ACTIONTYPES, ACTIONTYPES2 site = environ.get("DOMAIN").strip() site_name = environ.get("SITE_NAME").strip() +@app.get("/emojis") +@auth_desired +def emojis(v): + emojis = (x.replace('.webp','') for x in os.listdir("files/assets/images/emojis")) + return render_template("emojis.html", v=v, emojis=emojis) + @app.get('/rules') @auth_desired def static_rules(v): - if not path.exists(f'./rules_{site_name}.html'): + if not path.exists(f'rules_{site_name}.html'): if v and v.admin_level > 1: return render_template('norules.html', v=v) else: abort(404) - with open(f'./rules_{site_name}.html', 'r') as f: + with open(f'rules_{site_name}.html', 'r') as f: rules = f.read() return render_template('rules.html', rules=rules, v=v) @@ -69,7 +75,7 @@ def participation_stats(v): @auth_required def chart(v): file = cached_chart() - return send_file(f"../{file}") + return send_file(f".{file}") @cache.memoize(timeout=86400) @@ -212,7 +218,7 @@ def log_item(id, v): @app.get("/assets/favicon.ico") def favicon(): - return send_file(f"./assets/images/{site_name}/icon.webp?v=190") + return send_file(f"assets/images/{site_name}/icon.webp?v=190") @app.get("/api") @auth_desired @@ -250,7 +256,7 @@ def archives(path): @app.get('/assets/') @limiter.exempt def static_service(path): - resp = make_response(send_from_directory('./assets', path)) + resp = make_response(send_from_directory('assets', path)) if request.path.endswith('.webp') or request.path.endswith('.gif') or request.path.endswith('.ttf') or request.path.endswith('.woff') or request.path.endswith('.woff2'): resp.headers.remove("Cache-Control") resp.headers.add("Cache-Control", "public, max-age=2628000") @@ -275,7 +281,7 @@ def images(path): @app.get("/robots.txt") def robots_txt(): - return send_file("./assets/robots.txt") + return send_file("assets/robots.txt") @app.get("/settings") @auth_required diff --git a/files/templates/marseys.html b/files/templates/emojis.html similarity index 56% rename from files/templates/marseys.html rename to files/templates/emojis.html index 0cecf8967..bb7d2f409 100644 --- a/files/templates/marseys.html +++ b/files/templates/emojis.html @@ -9,15 +9,15 @@ # Name - Marsey + Emoji -{% for marsey in marseys %} +{% for emoji in emojis %} {{loop.index}} - {{marsey}} - :{{marsey}}: + {{emoji}} + :{{emoji}}: {% endfor %}