From 709598ebfb6087d01a282a164ce0e96d97d1f631 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 27 Jul 2021 02:35:01 +0200 Subject: [PATCH] fddf --- drama/classes/domains.py | 1 - drama/classes/submission.py | 2 +- drama/helpers/sanitize.py | 30 +++++++++++------------- drama/routes/admin.py | 1 - drama/routes/comments.py | 4 ++-- drama/routes/posts.py | 4 ++-- drama/routes/settings.py | 2 +- drama/routes/static.py | 15 ------------ drama/templates/admin/manage_domain.html | 3 --- drama/templates/embeds/submission.html | 2 +- drama/templates/formatting.html | 2 -- 11 files changed, 21 insertions(+), 45 deletions(-) diff --git a/drama/classes/domains.py b/drama/classes/domains.py index 8cb870ceb..694829773 100644 --- a/drama/classes/domains.py +++ b/drama/classes/domains.py @@ -19,7 +19,6 @@ class Domain(Base): can_submit = Column(Boolean, default=True) can_comment = Column(Boolean, default=True) reason = Column(Integer, default=0) - show_thumbnail = Column(Boolean, default=False) embed_function = Column(String(64)) embed_template = Column(String(32)) diff --git a/drama/classes/submission.py b/drama/classes/submission.py index add9e5fc8..8d6c3691f 100644 --- a/drama/classes/submission.py +++ b/drama/classes/submission.py @@ -410,7 +410,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): @property def is_image(self): - if self.url: return self.url.endswith('jpg') or self.url.endswith('png') or self.url.endswith('.gif') or self.url.endswith('jpeg') or self.url.endswith('?maxwidth=9999') or self.url.endswith('?maxwidth=8888') + if self.url: return self.url.lower().endswith('jpg') or self.url.lower().endswith('png') or self.url.lower().endswith('.gif') or self.url.lower().endswith('jpeg') or self.ur.lower()l.endswith('?maxwidth=9999') or self.url.lower().endswith('?maxwidth=8888') else: return False @property diff --git a/drama/helpers/sanitize.py b/drama/helpers/sanitize.py index a01dea623..e2a3d757c 100644 --- a/drama/helpers/sanitize.py +++ b/drama/helpers/sanitize.py @@ -123,26 +123,24 @@ def sanitize(text, linkgen=False, flair=False): netloc = urlparse(url).netloc domain = get_domain(netloc) - if not(netloc) or (domain and domain.show_thumbnail): + if "profile-pic-20" not in tag.get("class", ""): + #print(tag.get('class')) + # set classes and wrap in link - if "profile-pic-20" not in tag.get("class", ""): - #print(tag.get('class')) - # set classes and wrap in link + tag["rel"] = "nofollow" + tag["style"] = "max-height: 100px; max-width: 100%;" + tag["class"] = "in-comment-image rounded-sm my-2" - tag["rel"] = "nofollow" - tag["style"] = "max-height: 100px; max-width: 100%;" - tag["class"] = "in-comment-image rounded-sm my-2" + link = soup.new_tag("a") + link["href"] = tag["src"] + link["rel"] = "nofollow noopener" + link["target"] = "_blank" - link = soup.new_tag("a") - link["href"] = tag["src"] - link["rel"] = "nofollow noopener" - link["target"] = "_blank" + link["onclick"] = f"expandDesktopImage('{tag['src']}');" + link["data-toggle"] = "modal" + link["data-target"] = "#expandImageModal" - link["onclick"] = f"expandDesktopImage('{tag['src']}');" - link["data-toggle"] = "modal" - link["data-target"] = "#expandImageModal" - - tag.wrap(link) + tag.wrap(link) else: # non-whitelisted images get replaced with links new_tag = soup.new_tag("a") diff --git a/drama/routes/admin.py b/drama/routes/admin.py index c1af7c697..1bf1a5391 100644 --- a/drama/routes/admin.py +++ b/drama/routes/admin.py @@ -931,7 +931,6 @@ def admin_ban_domain(v): can_submit=False, can_comment=False, reason=reason, - show_thumbnail=False, embed_function=None, embed_template=None ) diff --git a/drama/routes/comments.py b/drama/routes/comments.py index 8bc2e2cb4..98df43b5d 100644 --- a/drama/routes/comments.py +++ b/drama/routes/comments.py @@ -264,7 +264,7 @@ def api_comment(v): if not body and not request.files.get('file'): return jsonify({"error":"You need to actually write something!"}), 400 - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', body, re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})') + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', body.lower(), re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})') body = body.replace("\n", "\n\n") with CustomRenderer(post_id=parent_id) as renderer: body_md = renderer.render(mistletoe.Document(body)) body_html = sanitize(body_md, linkgen=True) @@ -649,7 +649,7 @@ def edit_comment(cid, v): if c.is_banned or c.deleted_utc > 0: abort(403) body = request.form.get("body", "")[0:10000] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', body, re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})') + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', body.lower(), re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})') body = body.replace("\n", "\n\n") with CustomRenderer(post_id=c.post.base36id) as renderer: body_md = renderer.render(mistletoe.Document(body)) body_html = sanitize(body_md, linkgen=True) diff --git a/drama/routes/posts.py b/drama/routes/posts.py index cfbb1d982..aa5988ec2 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -260,7 +260,7 @@ def edit_post(pid, v): abort(403) body = request.form.get("body", "") - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', body, re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})') + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', body.lower(), re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})') body = body.replace("\n", "\n\n") with CustomRenderer() as renderer: body_md = renderer.render(mistletoe.Document(body)) @@ -794,7 +794,7 @@ def submit_post(v): } # render text - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', body, re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})') + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', body.lower(), re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})') body = body.replace("\n", "\n\n") with CustomRenderer() as renderer: body_md = renderer.render(mistletoe.Document(body)) diff --git a/drama/routes/settings.py b/drama/routes/settings.py index 699643d0b..2beffe841 100644 --- a/drama/routes/settings.py +++ b/drama/routes/settings.py @@ -69,7 +69,7 @@ def settings_profile_post(v): v=v, error="You didn't change anything") - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', bio, re.MULTILINE): bio = bio.replace(i.group(1), f'![]({i.group(1)})') + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif))', bio.lower(), re.MULTILINE): bio = bio.replace(i.group(1), f'![]({i.group(1)})') bio = bio.replace("\n", "\n\n") with CustomRenderer() as renderer: bio_html = renderer.render(mistletoe.Document(bio)) diff --git a/drama/routes/static.py b/drama/routes/static.py index 3dfe0dfa4..c0c38d227 100644 --- a/drama/routes/static.py +++ b/drama/routes/static.py @@ -206,21 +206,6 @@ def settings_security(v): msg=request.args.get("msg") or None ) -@app.route("/imagehosts", methods=["GET"]) -def info_image_hosts(): - - sites = g.db.query(Domain).filter_by( - show_thumbnail=True).order_by( - Domain.domain.asc()).all() - - sites = [x.domain for x in sites] - - text = "\n".join(sites) - - resp = make_response(text) - resp.mimetype = "text/plain" - return resp - @app.route("/dismiss_mobile_tip", methods=["POST"]) def dismiss_mobile_tip(): diff --git a/drama/templates/admin/manage_domain.html b/drama/templates/admin/manage_domain.html index ab113aeac..631986c0c 100644 --- a/drama/templates/admin/manage_domain.html +++ b/drama/templates/admin/manage_domain.html @@ -23,9 +23,6 @@

reason

{{domain.reason_text}}

-

show_thumbnail

-

{{domain.show_thumbnail}}

-

embed_function

{{domain.embed_function}}

diff --git a/drama/templates/embeds/submission.html b/drama/templates/embeds/submission.html index 1d186b492..bf33037a6 100644 --- a/drama/templates/embeds/submission.html +++ b/drama/templates/embeds/submission.html @@ -102,7 +102,7 @@
- {% if p.is_image and p.domain_obj and p.domain_obj.show_thumbnail %}Unable to anonymously load image + {% if p.is_image %}Unable to anonymously load image
{{p.domain|truncate(30, True)}}
{% endif %}
diff --git a/drama/templates/formatting.html b/drama/templates/formatting.html index a41f15c5f..b891ab3de 100644 --- a/drama/templates/formatting.html +++ b/drama/templates/formatting.html @@ -59,8 +59,6 @@ On Drama, you can use Markdown formatting. -

* We have customized image embeds to add pop-overs and operate on a whitelist system. Embeds from known safe image hosts will use a pop-up display as demonstrated here. Attempted embeds to non-whitelisted sites will be converted into a link. The whitelist may be viewed here.

- {% filter markdown %} ## Block formatting