From bbb7046a764a9dc6e7ad1ecf00c22f3d40937fad Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 13 Aug 2021 20:53:11 +0200 Subject: [PATCH 01/11] fdfd --- files/helpers/jinja2.py | 5 +++-- files/routes/comments.py | 4 ++-- files/routes/front.py | 2 +- files/routes/posts.py | 2 +- files/routes/users.py | 4 ++-- files/templates/submission.html | 9 +++++++-- files/templates/submission_banned.html | 4 ++-- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 8c6e63e09..46eb6a7e7 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -13,9 +13,10 @@ def app_config(x): return app.config.get(x) @app.template_filter("post_embed") -def crosspost_embed(id): +def post_embed(id): - id = int(id) + try: id = int(id) + except: return None p = get_post(id, graceful=True) diff --git a/files/routes/comments.py b/files/routes/comments.py index 3c2e74cee..955fe2911 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -35,8 +35,8 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): if not v and "logged_out" not in request.path: return redirect(f"/logged_out/comment/{cid}") - if v and "logged_out" in request.full_path: return redirect(f"/comment/{cid}") - + if v and "logged_out" in request.full_path: v = None + try: cid = int(cid) except: try: cid = int(cid, 36) diff --git a/files/routes/front.py b/files/routes/front.py index 50f860687..75d69e477 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -191,7 +191,7 @@ def front_all(v): if not v and request.path == "/": return redirect("/logged_out") - if v and "logged_out" in request.full_path: return redirect("/") + if v and "logged_out" in request.full_path: v = None try: page = int(request.args.get("page") or 1) except: abort(400) diff --git a/files/routes/posts.py b/files/routes/posts.py index 1cb9a5ee2..76f309e7d 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -54,7 +54,7 @@ def post_id(pid, anything=None, v=None): if not v and "logged_out" not in request.path: return redirect(f"/logged_out/post/{pid}") - if v and "logged_out" in request.full_path: return redirect(f"/post/{pid}") + if v and "logged_out" in request.full_path: v = None try: pid = int(pid) except Exception as e: pass diff --git a/files/routes/users.py b/files/routes/users.py index 632ca2f0c..bf930aa9e 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -281,7 +281,7 @@ def u_username(username, v=None): if not v and "logged_out" not in request.path: return redirect(f"/logged_out/@{username}") - if v and "logged_out" in request.full_path: return redirect(f"/@{username}") + if v and "logged_out" in request.full_path: v = None # username is unique so at most this returns one result. Otherwise 404 @@ -402,7 +402,7 @@ def u_username_comments(username, v=None): if not v and "logged_out" not in request.path: return redirect(f"/logged_out/@{username}/comments") - if v and "logged_out" in request.full_path: return redirect(f"/@{username}/comments") + if v and "logged_out" in request.full_path: v = None # username is unique so at most this returns one result. Otherwise 404 diff --git a/files/templates/submission.html b/files/templates/submission.html index 8e41d5d02..38616dc7b 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -9,7 +9,12 @@ {% endif %} +{% if v %} +{% set title=p.realtitle(v) %} +{% else %} {% set title=p.title %} +{% endif %} + {% set ups=p.upvotes_fuzzed %} {% set downs=p.downvotes_fuzzed %} {% set score=ups-downs %} @@ -58,7 +63,7 @@ {% if p.edited_utc %}{% endif %} - + @@ -69,7 +74,7 @@ - + diff --git a/files/templates/submission_banned.html b/files/templates/submission_banned.html index 5624e0b34..29d8ae90d 100644 --- a/files/templates/submission_banned.html +++ b/files/templates/submission_banned.html @@ -10,7 +10,7 @@ {% endif %} {% block title %} -{{p.title}} +{{p.realtitle(v)}} {% if p.is_banned %} {% else %} @@ -55,7 +55,7 @@
-
{{p.title}}
+
{{p.realtitle(v)}}
From 507b742b972413e323dc04cea0d5d4faa355f863 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 13 Aug 2021 20:55:59 +0200 Subject: [PATCH 02/11] fddf --- files/helpers/jinja2.py | 5 ++--- files/templates/submission.html | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 46eb6a7e7..c9c21ffa4 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -13,12 +13,11 @@ def app_config(x): return app.config.get(x) @app.template_filter("post_embed") -def post_embed(id): +def post_embed(id, v): try: id = int(id) except: return None p = get_post(id, graceful=True) - if hasattr(g, 'v') and g.v: return render_template("submission_listing.html", listing=[p], v=g.v) - else: return render_template("submission_listing.html", listing=[p], postembed=True) \ No newline at end of file + return render_template("submission_listing.html", listing=[p], v=v) \ No newline at end of file diff --git a/files/templates/submission.html b/files/templates/submission.html index 38616dc7b..1fb37df69 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -308,7 +308,7 @@
- {{ p.embed_url | post_embed | safe }} + {{ p.embed_url | post_embed(v) | safe }}
From 68d9fa2dec5288afeab4018a95fa6f2f96594308 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 13 Aug 2021 20:57:32 +0200 Subject: [PATCH 03/11] fdfd --- files/templates/errors/502.html | 2 +- files/templates/header.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/files/templates/errors/502.html b/files/templates/errors/502.html index 8cd53dd8f..c1cb02cf5 100644 --- a/files/templates/errors/502.html +++ b/files/templates/errors/502.html @@ -37,7 +37,7 @@
diff --git a/giphy.py b/giphy.py new file mode 100644 index 000000000..28b2bfadf --- /dev/null +++ b/giphy.py @@ -0,0 +1,22 @@ +from flask import * +from os import environ +import requests + +from files.__main__ import app + +GIPHY_KEY = environ.get('GIPHY_KEY').rstrip() + + +@app.route("/giphy", methods=["GET"]) +@app.route("/giphy", methods=["GET"]) +def giphy(): + + searchTerm = request.args.get("searchTerm", "") + limit = int(request.args.get("limit", "")) + if searchTerm and limit: + url = f"https://api.giphy.com/v1/gifs/search?q={searchTerm}&api_key={GIPHY_KEY}&limit={limit}" + elif searchTerm and not limit: + url = f"https://api.giphy.com/v1/gifs/search?q={searchTerm}&api_key={GIPHY_KEY}&limit=48" + else: + url = f"https://api.giphy.com/v1/gifs?api_key={GIPHY_KEY}&limit=48" + return jsonify(requests.get(url).json()) \ No newline at end of file diff --git a/readme.md b/readme.md index 85759a978..115d8af12 100644 --- a/readme.md +++ b/readme.md @@ -24,7 +24,7 @@ docker-compose up 4- That's it! Visit `localhost` in your browser. -5- Optional: to configure the site settings and successsfully integrate it with the external services we use (hcaptcha, cloudflare, discord, tenor and mailgun), please edit the variables in the docker-compose.yml file. +5- Optional: to configure the site settings and successsfully integrate it with the external services we use (hcaptcha, cloudflare, discord, giphy and mailgun), please edit the variables in the docker-compose.yml file. --- @@ -51,7 +51,7 @@ source setup 4- That's it. Visit `localhost` in your browser. -5- Optional: to configure the site settings and successsfully integrate it with the external services we use (hcaptcha, cloudflare, discord, tenor and mailgun), please run this command and edit the variables: +5- Optional: to configure the site settings and successsfully integrate it with the external services we use (hcaptcha, cloudflare, discord, giphy and mailgun), please run this command and edit the variables: ``` nano /drama/docker-compose.yml From 5bbf0cc4c0c0ad78b268502c76bb26cbaaf06e60 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 13 Aug 2021 23:05:04 +0200 Subject: [PATCH 09/11] fd --- files/routes/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/routes/__init__.py b/files/routes/__init__.py index bf40d037f..cbddc7e96 100644 --- a/files/routes/__init__.py +++ b/files/routes/__init__.py @@ -13,4 +13,5 @@ from .static import * from .users import * from .votes import * from .feeds import * -from .awards import * \ No newline at end of file +from .awards import * +from .giphy import * \ No newline at end of file From 809c02fae121c4f098433f1812ec271f1c6a7b90 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 13 Aug 2021 23:11:55 +0200 Subject: [PATCH 10/11] fddf --- files/routes/login.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/routes/login.py b/files/routes/login.py index fb5198bb2..7482d6879 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -125,7 +125,8 @@ def login_post(): # check for previous page redir = request.form.get("redirect", "/") - if "logged_out" not in redir: return redirect(redir) + if "/logged_out" not in redir: return redirect(redir) + else: return redirect(redir.replace("/logged_out", "")) @app.get("/me") From 033f5a6e7f0073d8f565e978b427f984ef5596c6 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 13 Aug 2021 23:12:11 +0200 Subject: [PATCH 11/11] fdfd --- files/routes/login.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/files/routes/login.py b/files/routes/login.py index 7482d6879..4cc84cda8 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -125,8 +125,7 @@ def login_post(): # check for previous page redir = request.form.get("redirect", "/") - if "/logged_out" not in redir: return redirect(redir) - else: return redirect(redir.replace("/logged_out", "")) + return redirect(redir.replace("/logged_out", "")) @app.get("/me")