From 0c2fcc50b4e444e03e8b94a506512a3f96690de6 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 13 Aug 2021 04:35:17 +0200 Subject: [PATCH] fdfd --- files/helpers/get.py | 5 +- files/helpers/jinja2.py | 13 ++- files/routes/posts.py | 36 +------- files/templates/embeds/comment.html | 122 ---------------------------- files/templates/embeds/post.html | 21 ----- files/templates/submission.html | 12 +++ 6 files changed, 29 insertions(+), 180 deletions(-) delete mode 100644 files/templates/embeds/comment.html delete mode 100644 files/templates/embeds/post.html diff --git a/files/helpers/get.py b/files/helpers/get.py index eb78014f6..f8458764e 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -1,9 +1,6 @@ from files.classes import * from flask import g -from sqlalchemy.orm import joinedload, aliased - -import re - +from sqlalchemy.orm import joinedload def get_user(username, v=None, graceful=False): diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 0227c509b..92f7eb63b 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -1,4 +1,5 @@ from files.__main__ import app +from .get import * @app.template_filter("full_link") @@ -9,4 +10,14 @@ def full_link(url): @app.template_filter("app_config") def app_config(x): - return app.config.get(x) \ No newline at end of file + return app.config.get(x) + +@app.template_filter("post_embed") +def crosspost_embed(id): + + p = get_post(id, graceful=True) + + return render_template( + "submission_listing.html", + listing=[p] + ) \ No newline at end of file diff --git a/files/routes/posts.py b/files/routes/posts.py index 4e8997438..0d52ef49f 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -495,29 +495,6 @@ def archiveorg(url): try: requests.get(f'https://web.archive.org/save/{url}', headers={'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}, timeout=100) except Exception as e: print(e) - -@app.route("/embed/post/", methods=["GET"]) -def embed_post_pid(pid): - - try: pid = int(pid) - except: abort(400) - - post = get_post(pid) - - return render_template("embeds/post.html", p=post) - - -@app.route("/embed/comment/", methods=["GET"]) -def embed_comment_cid(cid, pid=None): - - try: cid = int(cid) - except: abort(400) - - comment = get_comment(cid) - - return render_template("embeds/comment.html", c=comment) - - @app.post("/submit") @limiter.limit("6/minute") @is_not_banned @@ -629,15 +606,10 @@ def submit_post(v): elif "instagram.com" in domain: embed = requests.get("https://graph.facebook.com/v9.0/instagram_oembed", params={"url":url,"access_token":environ.get("FACEBOOK_TOKEN","").strip(),"omitscript":'true'}, headers={"User-Agent": app.config["UserAgent"]}).json()["html"] - elif app.config['SERVER_NAME'] in domain: - try: - if "/?context=" in url: - id = url.split("/?context=")[0].split("/")[1] - embed = f"https://{app.config['SERVER_NAME']}/embed/comment/{id}" - elif "/post/" in url: - id = url.split("/post/")[1].split("/")[0] - embed = f"https://{app.config['SERVER_NAME']}/embed/post/{id}" - except: embed = None + elif app.config['SERVER_NAME'] in domain and "/post/" in url: + id = url.split("/post/")[1] + if "/" in id: id = id.split("/")[0] + embed = id else: embed = None diff --git a/files/templates/embeds/comment.html b/files/templates/embeds/comment.html deleted file mode 100644 index 0f192bacd..000000000 --- a/files/templates/embeds/comment.html +++ /dev/null @@ -1,122 +0,0 @@ -{% extends "embeds/embed_default.html" %} - -{% set score=c.score_fuzzed %} - -{% block title %} -@{{c.author.username}} comments on "{{c.post.title}}" - -{% endblock %} - - -{% block content %} - - -
- - - - - -
- -
- - - -
- {{c.body_html | safe}} -
- - -
-
    - - - -
  • -
  • - - -
  • - {{score}}
  • - -
  • Copy link -
  • -
  • - -
  • -
  • - -
  • - -
  • -
  • -
  • -{{score}} -
  • - -
  • -
  • -
- -
-
- - - - - -
-{% endblock %} \ No newline at end of file diff --git a/files/templates/embeds/post.html b/files/templates/embeds/post.html deleted file mode 100644 index 299f7f265..000000000 --- a/files/templates/embeds/post.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends "embeds/embed_default.html" %} - -{% block title %} -{{p.title | safe}} - -{% endblock %} - -{% block pagetype %}thread{% endblock %} - - -{% block content %} -
-
-
- {% with listing = [p] %} - {% include "submission_listing.html" %} - {% endwith %} -
-
-
-{% endblock %} \ No newline at end of file diff --git a/files/templates/submission.html b/files/templates/submission.html index 1724f711b..8e41d5d02 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -298,6 +298,18 @@
{% endif %} + {% if p.embed_url and "http" not in p.embed_url %} +
+
+
+
+ {{ p.embed_url | post_embed | safe }} +
+
+
+
+ {% endif %} +