From 397dca9a8322d12a5a690c046ea997e04ba30229 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 18 Mar 2022 21:05:54 +0200 Subject: [PATCH] publish fix --- files/classes/comment.py | 2 +- files/classes/submission.py | 6 +++--- files/helpers/sanitize.py | 4 +--- files/routes/posts.py | 6 +++--- files/templates/authforms.html | 4 ++-- files/templates/default.html | 8 ++++---- files/templates/log.html | 4 ++-- files/templates/login.html | 4 ++-- files/templates/login_2fa.html | 2 +- files/templates/post_actions.html | 9 ++++++--- files/templates/settings.html | 2 +- files/templates/settings2.html | 4 ++-- files/templates/sign_up.html | 2 +- files/templates/sign_up_failed_ref.html | 2 +- files/templates/submit.html | 6 +++--- 15 files changed, 33 insertions(+), 32 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 571691178..1e1e5d819 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -348,7 +348,7 @@ class Comment(Base): if v.teddit: body = body.replace("old.reddit.com", "teddit.net") elif not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com") - if v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") + if v.nitter and not '/i/' in body and '/retweets' not in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") if v and v.controversial: captured = [] diff --git a/files/classes/submission.py b/files/classes/submission.py index f7976eaea..779d12e9a 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -354,7 +354,7 @@ class Submission(Base): if v.controversial: url += "&sort=controversial" return url elif self.url: - if v and v.nitter and not '/i/' in self.url: return self.url.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") + if v and v.nitter and '/i/' not in self.url and '/retweets' not in self.url: return self.url.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") if self.url.startswith('/'): return SITE_FULL + self.url return self.url else: return "" @@ -370,7 +370,7 @@ class Submission(Base): if v.teddit: body = body.replace("old.reddit.com", "teddit.net") elif not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com") - if v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") + if v.nitter and '/i/' not in body and '/retweets' not in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") if v and v.shadowbanned and v.id == self.author_id and 86400 > time.time() - self.created_utc > 20: ti = max(int((time.time() - self.created_utc)/60), 1) @@ -436,7 +436,7 @@ class Submission(Base): if v.teddit: body = body.replace("old.reddit.com", "teddit.net") elif not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com") - if v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") + if v.nitter and '/i/' not in body and '/retweets' not in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") return body diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 65be0a660..794104c82 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -276,7 +276,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = re.sub(f'(?', sanitized, flags=re.I|re.A) if comment: marseys_used.add(emoji) - sanitized = sanitized.replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").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("m.wikipedia.org", "wikipedia.org").replace("https://m.youtube", "https://youtube").replace("https://www.youtube", "https://youtube") + sanitized = sanitized.replace("nitter.net", "twitter.com").replace("old.reddit.com/gallery", "reddit.com/gallery").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").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("m.wikipedia.org", "wikipedia.org").replace("https://m.youtube", "https://youtube").replace("https://www.youtube", "https://youtube").replace("https://www.twitter", "https://twitter") if "https://youtube.com/watch?v=" in sanitized: sanitized = sanitized.replace("?t=", "&t=") @@ -302,8 +302,6 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): for rd in ["://reddit.com", "://new.reddit.com", "://www.reddit.com", "://redd.it", "://libredd.it"]: sanitized = sanitized.replace(rd, "://old.reddit.com") - sanitized = sanitized.replace("old.reddit.com/gallery", "reddit.com/gallery") - sanitized = unlinked_regex.sub(r'\1\2', sanitized) diff --git a/files/routes/posts.py b/files/routes/posts.py index 162e95761..8d8e9f867 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -98,7 +98,7 @@ def publish(pid, v): g.db.commit() - return redirect(p.permalink) + return redirect(post.permalink) @app.get("/submit") @app.get("/h//submit") @@ -839,6 +839,8 @@ def submit_post(v, sub=None): embed = None if url: + url = url.replace("nitter.net", "twitter.com").replace("old.reddit.com/gallery", "reddit.com/gallery").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").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("m.wikipedia.org", "wikipedia.org").replace("https://m.youtube", "https://youtube").replace("https://www.youtube", "https://youtube").replace("https://www.twitter", "https://twitter") + if "/i.imgur.com/" in url: url = url.replace(".png", ".webp").replace(".jpg", ".webp").replace(".jpeg", ".webp") elif "/media.giphy.com/" in url or "/c.tenor.com/" in url: url = url.replace(".gif", ".webp") elif "/i.ibb.com/" in url: url = url.replace(".png", ".webp").replace(".jpg", ".webp").replace(".jpeg", ".webp").replace(".gif", ".webp") @@ -846,8 +848,6 @@ def submit_post(v, sub=None): for rd in ("://reddit.com", "://new.reddit.com", "://www.reddit.com", "://redd.it", "://libredd.it", "://teddit.net"): url = url.replace(rd, "://old.reddit.com") - url = url.replace("nitter.net", "twitter.com").replace("old.reddit.com/gallery", "reddit.com/gallery").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").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("m.wikipedia.org", "wikipedia.org").replace("https://m.youtube", "https://youtube").replace("https://www.youtube", "https://youtube") - if url.startswith("https://streamable.com/") and not url.startswith("https://streamable.com/e/"): url = url.replace("https://streamable.com/", "https://streamable.com/e/") parsed_url = urlparse(url) diff --git a/files/templates/authforms.html b/files/templates/authforms.html index b74ccea67..54929e1e6 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,7 +15,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 28e7544c6..0bdf6ae60 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -7,8 +7,8 @@ {% if v %} - - + + {% if v.agendaposter %} - - + + {% endif %} {% if sub and sub.css and not request.path.endswith('settings') %} diff --git a/files/templates/log.html b/files/templates/log.html index ed52b8281..d4b016a1d 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index 71b862e68..14db001a6 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -18,8 +18,8 @@ {% endblock %} - - + + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index a799f9e53..43fede698 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -14,7 +14,7 @@ 2-Step Login - {{SITE_NAME}} - + diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index e8d6c2133..1134cd094 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -1,13 +1,16 @@ -{% if not p.ghost %}Votes{% endif %} - {% if v and v.id==p.author_id %} {% if p.private %} - Publish +
+ + +
{% endif %} {% endif %} +{% if not p.ghost %}Votes{% endif %} + {% if v %} Give Award {% endif %} diff --git a/files/templates/settings.html b/files/templates/settings.html index ec5c3ed78..6a6a82f2f 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -34,7 +34,7 @@ - + {% if v.agendaposter %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 5d3d42aeb..d25d50c37 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}Sign up - {{SITE_NAME}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index d3c9e1236..54bf7466f 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}{{SITE_NAME}}{% endif %} - + diff --git a/files/templates/submit.html b/files/templates/submit.html index ceb961da8..806487c04 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -26,7 +26,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - - + + {% endif %} {% endblock %}