From ab7faaf5b88c0e89bd3d8d3de470c70429b87bde Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 9 Oct 2021 17:29:49 +0200 Subject: [PATCH] fdsfsd --- files/routes/posts.py | 54 +++++++++++++++++-------------------- files/templates/header.html | 2 +- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 4db7c6d82..3e94a1630 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -556,38 +556,32 @@ def submit_post(v): Submission.body == body ).first() - if dup: - return redirect(dup.permalink) + if dup: return redirect(dup.permalink) + if domain: + domain_obj = get_domain(domain) + if domain_obj: + if domain_obj.reason==4: v.ban(days=30, reason="Digitally malicious content") + elif domain_obj.reason==7: v.ban(reason="Sexualizing minors") - domain_obj = get_domain(domain) - if domain_obj: - if domain_obj.reason==4: - v.ban(days=30, reason="Digitally malicious content") - elif domain_obj.reason==7: - v.ban(reason="Sexualizing minors") - - if request.headers.get("Authorization"): return {"error":"ToS violation"}, 400 - else: return render_template("submit.html", v=v, error="ToS Violation", title=title, url=url, body=request.values.get("body", "")), 400 - - if "twitter.com" in domain: - try: embed = requests.get("https://publish.twitter.com/oembed", params={"url":url, "omit_script":"t"}).json()["html"] - except: embed = None - - elif "youtu" in domain: - try: - yt_id = re.match(re.compile("^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|shorts\/|\&v=)([^#\&\?]*).*"), url).group(2) - params = parse_qs(urlparse(url).query) - t = params.get('t', params.get('start', [0]))[0] - if t: embed = f"https://youtube.com/embed/{yt_id}?start={t}" - else: embed = f"https://youtube.com/embed/{yt_id}" - except: embed = None - - elif app.config['SERVER_NAME'] in domain and "/post/" in url and "context" not in url: - id = url.split("/post/")[1] - if "/" in id: id = id.split("/")[0] - embed = id - + if request.headers.get("Authorization"): return {"error":"ToS violation"}, 400 + else: return render_template("submit.html", v=v, error="ToS Violation", title=title, url=url, body=request.values.get("body", "")), 400 + elif "twitter.com" in domain: + try: embed = requests.get("https://publish.twitter.com/oembed", params={"url":url, "omit_script":"t"}).json()["html"] + except: embed = None + elif "youtu" in domain: + try: + yt_id = re.match(re.compile("^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|shorts\/|\&v=)([^#\&\?]*).*"), url).group(2) + params = parse_qs(urlparse(url).query) + t = params.get('t', params.get('start', [0]))[0] + if t: embed = f"https://youtube.com/embed/{yt_id}?start={t}" + else: embed = f"https://youtube.com/embed/{yt_id}" + except: embed = None + elif app.config['SERVER_NAME'] in domain and "/post/" in url and "context" not in url: + id = url.split("/post/")[1] + if "/" in id: id = id.split("/")[0] + embed = id + else: embed = None else: embed = None now = int(time.time()) diff --git a/files/templates/header.html b/files/templates/header.html index 7279ed83d..c39e68099 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -184,7 +184,7 @@ Source code - Report bugs + Report bugs Discord {% if 'pcm' not in request.host %}Donate{% endif %}