diff --git a/files/routes/posts.py b/files/routes/posts.py index 1776a8622a..5540a45e23 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -95,7 +95,7 @@ def submit_get(v, sub=None): if request.path.startswith('/s/') and not sub: abort(404) - return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, sub=sub) + return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, sub=sub) @app.get("/post/") @app.get("/post//") @@ -724,7 +724,10 @@ def thumbnail_thread(pid): for t in ("submission","comment"): word = random.choice(('rdrama','marsey')) - for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={word}&size=1').json()["data"]: + try: data = requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={word}&size=1').json()["data"] + except: break + + for i in data: body_html = sanitize(f'New {word} mention: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) @@ -769,8 +772,11 @@ def thumbnail_thread(pid): if SITE == 'pcmemes.net': for t in ("submission","comment"): - for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q=pcmemes.net&size=1').json()["data"]: + try: data = requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q=pcmemes.net&size=1').json()["data"] + except: break + + for i in data: body_html = sanitize(f'New pcmemes mention: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html, level=1, sentto=0).first() @@ -882,7 +888,7 @@ def submit_post(v, sub=None): if domain_obj: reason = f"Remove the {domain_obj.domain} link from your post and try again. {domain_obj.reason}" if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error":reason}, 400 - return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, error=reason, title=title, url=url, body=request.values.get("body", "")), 400 + return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, error=reason, title=title, url=url, body=request.values.get("body", "")), 400 elif "twitter.com" == domain: try: embed = requests.get("https://publish.twitter.com/oembed", timeout=5, params={"url":url, "omit_script":"t"}).json()["html"] except: embed = None @@ -904,16 +910,16 @@ def submit_post(v, sub=None): if not url and not request.values.get("body") and not request.files.get("file", None): if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "`url` or `body` parameter required."}, 400 - return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, error="Please enter a url or some text.", title=title, url=url, body=request.values.get("body", "")), 400 + return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, error="Please enter a url or some text.", title=title, url=url, body=request.values.get("body", "")), 400 if not title: if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "Please enter a better title"}, 400 - return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, error="Please enter a better title.", title=title, url=url, body=request.values.get("body", "")), 400 + return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, error="Please enter a better title.", title=title, url=url, body=request.values.get("body", "")), 400 elif len(title) > 500: if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "500 character limit for titles"}, 400 - else: render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, error="500 character limit for titles.", title=title[:500], url=url, body=request.values.get("body", "")), 400 + else: render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, error="500 character limit for titles.", title=title[:500], url=url, body=request.values.get("body", "")), 400 if v.marseyawarded: marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, re.A)) @@ -982,12 +988,12 @@ def submit_post(v, sub=None): if len(str(body)) > 20000: if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error":"There's a 20000 character limit for text body."}, 400 - return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, error="There's a 20000 character limit for text body.", title=title, url=url, body=request.values.get("body", "")), 400 + return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, error="There's a 20000 character limit for text body.", title=title, url=url, body=request.values.get("body", "")), 400 if len(url) > 2048: if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error":"2048 character limit for URLs."}, 400 - return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, error="2048 character limit for URLs.", title=title, url=url,body=request.values.get("body", "")), 400 + return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, error="2048 character limit for URLs.", title=title, url=url,body=request.values.get("body", "")), 400 for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') @@ -1025,7 +1031,7 @@ def submit_post(v, sub=None): body += f"\n\n{url}" else: if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "Image/Video files only"}, 400 - return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, error="Image/Video files only."), 400 + return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, error="Image/Video files only."), 400 if '#fortune' in body: body = body.replace('#fortune', '') @@ -1048,7 +1054,7 @@ def submit_post(v, sub=None): reason = f"Remove the {ban.domain} link from your post and try again." if ban.reason: reason += f" {ban.reason}" if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": reason}, 403 - return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, error=reason, title=title, url=url, body=request.values.get("body", "")), 403 + return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, error=reason, title=title, url=url, body=request.values.get("body", "")), 403 if v.club_allowed == False: club = False else: club = bool(request.values.get("club","")) @@ -1134,7 +1140,7 @@ def submit_post(v, sub=None): new_post.url = url else: if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "File type not allowed"}, 400 - return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).all()), v=v, error="File type not allowed.", title=title, body=request.values.get("body", "")), 400 + return render_template("submit.html", SUBS=() if SITE_NAME == 'Drama' else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()), v=v, error="File type not allowed.", title=title, body=request.values.get("body", "")), 400 if not new_post.thumburl and new_post.url: diff --git a/files/routes/static.py b/files/routes/static.py index ba0a0fe437..5f52974ed6 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -278,7 +278,7 @@ def submit_contact(v): body = request.values.get("message") if not body: abort(400) - body = f'This message has been sent automatically to all admins via [/contact](/contact), user email is "{v.email}"\n\nMessage:\n\n' + body + body = f'This message has been sent automatically to all admins via [/contact](/contact)\n\nMessage:\n\n' + body body_html = sanitize(body, noimages=True) if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": diff --git a/files/routes/subs.py b/files/routes/subs.py index 7bad619799..b198099b78 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -7,7 +7,7 @@ from .front import frontlist valid_sub_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$") @app.get("/s//mods") -@auth_required +@is_not_permabanned def mods(v, sub): sub = g.db.query(Sub).filter_by(name=sub.lower()).one_or_none() if not sub: abort(404) @@ -18,7 +18,7 @@ def mods(v, sub): @app.post("/s//add_mod") -@auth_required +@is_not_permabanned def add_mod(v, sub): sub = g.db.query(Sub).filter_by(name=sub.lower()).one_or_none() if not sub: abort(404) @@ -43,13 +43,13 @@ def add_mod(v, sub): @app.get("/create_sub") -@auth_required +@is_not_permabanned def create_sub(v): return render_template("sub/create_sub.html", v=v) @app.post("/create_sub") -@auth_required +@is_not_permabanned def create_sub2(v): name = request.values.get('name') if not name: abort(400) @@ -77,7 +77,7 @@ def create_sub2(v): return redirect(f'/s/{sub.name}') @app.post("/kick/") -@auth_required +@is_not_permabanned def kick(v, pid): try: pid = int(pid) except: abort(400) @@ -97,7 +97,7 @@ def kick(v, pid): @app.get('/s//settings') -@auth_required +@is_not_permabanned def sub_settings(v, sub): sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() if not sub: abort(404) @@ -109,7 +109,7 @@ def sub_settings(v, sub): @app.post('/s//sidebar') @limiter.limit("1/second;30/minute;200/hour;1000/day") -@auth_required +@is_not_permabanned def post_sub_sidebar(v, sub): sub = g.db.query(Sub).filter_by(name=sub.lower()).one_or_none() if not sub: abort(404) @@ -133,7 +133,7 @@ def post_sub_sidebar(v, sub): @app.post("/s//banner") @limiter.limit("1/second;30/minute;200/hour;1000/day") -@auth_required +@is_not_permabanned def sub_banner(v, sub): if v and v.patron: if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 8 MB."}, 413 @@ -164,7 +164,7 @@ def sub_banner(v, sub): @app.post("/s//sidebar_image") @limiter.limit("1/second;30/minute;200/hour;1000/day") -@auth_required +@is_not_permabanned def sub_sidebar(v, sub): if v and v.patron: if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 8 MB."}, 413 @@ -190,12 +190,4 @@ def sub_sidebar(v, sub): g.db.add(sub) g.db.commit() - return redirect(f'/s/{sub.name}/settings') - - -#mods id seq -#css -#exile -#guild mod log -#remove mod -#search sub \ No newline at end of file + return redirect(f'/s/{sub.name}/settings') \ No newline at end of file diff --git a/files/templates/authforms.html b/files/templates/authforms.html index c14fb24e59..324e242253 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 2782fdf66d..8adc75f340 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -8,7 +8,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} @@ -225,7 +225,7 @@ {% elif sub %} - sub banner + /s/{[sub.name]} banner {% else %} @@ -276,7 +276,7 @@ {% endblock %} - {% if home %} + {% if home or sub and (request.path.startswith('/post') or request.path.startswith('/comment')) %} {% block sidebar %} {% include "sidebar_" + SITE_NAME + ".html" %} {% endblock %} diff --git a/files/templates/header.html b/files/templates/header.html index 499d172619..c57569f2ad 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -35,7 +35,7 @@ {% set icon = ('marseyblm','marseykween','marseydynamite','marseyblack','marseymyeisha','marseyetika','marseyobama','marseyblackcop','marseysosa','marseyblackface')|random() %} header icon {% else %} - header icon + header icon {% endif %} {% if SITE_NAME == 'Drama' %} diff --git a/files/templates/log.html b/files/templates/log.html index f1c9d86454..15f0a33196 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 d48c6cef50..e09e189adf 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -19,7 +19,7 @@ - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 4517c8730d..105217bbe8 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/settings.html b/files/templates/settings.html index ae504ca09a..82107a760f 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 6c28f1374a..9fede667ee 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 07364e220e..bc8cae341b 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/sub/settings.html b/files/templates/sub/settings.html index ec617343ae..749a5c0b78 100644 --- a/files/templates/sub/settings.html +++ b/files/templates/sub/settings.html @@ -57,7 +57,7 @@
- +
diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 4de2d3f5be..541848e906 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -296,7 +296,7 @@ {% if p.sub and v.mods(p.sub) %} - Kick + Kick {% endif %} diff --git a/files/templates/submit.html b/files/templates/submit.html index 51385edd43..088911a207 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -26,7 +26,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - + {% endif %} {% endblock %}