From 035d37b13447d8992adbe061d69b5af0b5b08b92 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 4 Feb 2022 20:35:39 +0200 Subject: [PATCH] fsd --- files/classes/comment.py | 4 +++- files/classes/mod_logs.py | 2 +- files/classes/submission.py | 13 ++++++------- files/helpers/const.py | 2 +- files/routes/comments.py | 8 ++++++-- files/routes/front.py | 22 ++++++++++----------- files/routes/posts.py | 26 ++++++++++++++----------- files/templates/header.html | 4 ++-- files/templates/home.html | 2 +- files/templates/submission_listing.html | 2 +- files/templates/submit.html | 2 +- schema.sql | 2 +- 12 files changed, 49 insertions(+), 40 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 199231186..7fa5bf0fa 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -232,7 +232,9 @@ class Comment(Base): @property @lazy def permalink(self): - if self.post and self.post.club: return f"{SITE_FULL}/comment/{self.id}?context=8#context" + if self.post and self.post.club: + if self.post.sub: f"{SITE_FULL}/s/{self.post.sub}/comment/{self.id}?context=8#context" + else: f"{SITE_FULL}/comment/{self.id}?context=8#context" if self.post: return f"{self.post.permalink}/{self.id}?context=8#context" else: return f"{SITE_FULL}/comment/{self.id}?context=8#context" diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index 23b3515cd..cdfc094e2 100644 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -80,7 +80,7 @@ class ModAction(Base): @lazy def string(self): - output = ACTIONTYPES[self.kind]["str"].format(self=self) + output = ACTIONTYPES[self.kind]["str"].format(self=self, cc=cc) if self.note: output += f" ({self.note})" diff --git a/files/classes/submission.py b/files/classes/submission.py index 7d86d1745..7157d4a32 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -29,7 +29,7 @@ class Submission(Base): distinguish_level = Column(Integer, default=0) stickied = Column(String) stickied_utc = Column(Integer) - hole = Column(String) + sub = Column(String) is_pinned = Column(Boolean, default=False) private = Column(Boolean, default=False) club = Column(Boolean, default=False) @@ -193,20 +193,19 @@ class Submission(Base): @property @lazy def shortlink(self): - if self.club: return f"/post/{self.id}" + link = f"/post/{self.id}" + if self.sub: link = f"/s/{self.sub}{link}" + + if self.club: return link output = self.title.lower() - output = re.sub('&\w{2,3};', '', output, re.A) - output = [re.sub('\W', '', word, re.A) for word in output.split()] output = [x for x in output if x][:6] - output = '-'.join(output) - if not output: output = '-' - return f"/post/{self.id}/{output}" + return f"{link}/{output}" @property @lazy diff --git a/files/helpers/const.py b/files/helpers/const.py index 61918e1d6..8070cfb54 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -560,4 +560,4 @@ FORTUNE_REPLIES = ('Your fortune: Allah Wills It',' no_pass_phrase = """

Sorry whiteboy, we're gonna need to see some ID before you start throwin that word around like it's nothing.\n\nTake a 10 minute time-out and come back when you've learned your lesson and/or paid reparations (by purchasing a BIPOC Approved™ Rdrama NWord Pass© from the shop) \n\nThis is an automated message; if you need help, you can message us here.

""" -holes = ('2balkan4u','2middleeast4u') \ No newline at end of file +subs = ('2balkan4u','2middleeast4u') \ No newline at end of file diff --git a/files/routes/comments.py b/files/routes/comments.py index 47268260c..c92edd62f 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -26,8 +26,12 @@ CF_HEADERS = {"Authorization": f"Bearer {CF_KEY}", "Content-Type": "application/ @app.get("/post///") @app.get("/logged_out/comment/") @app.get("/logged_out/post///") +@app.get("/s//comment/") +@app.get("/s//post///") +@app.get("/logged_out/s//comment/") +@app.get("/logged_out/s//post///") @auth_desired -def post_pid_comment_cid(cid, pid=None, anything=None, v=None): +def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): if not v and not request.path.startswith('/logged_out'): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") @@ -127,7 +131,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): else: if post.is_banned and not (v and (v.admin_level > 1 or post.author_id == v.id)): template = "submission_banned.html" else: template = "submission.html" - return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True, hole=post.hole) + return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True, sub=post.sub) @app.post("/comment") @limiter.limit("1/second;20/minute;200/hour;1000/day") diff --git a/files/routes/front.py b/files/routes/front.py index 7b1b5a727..c266bd7da 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -128,12 +128,12 @@ def notifications(v): @app.get("/") @app.get("/logged_out") -@app.get("/") -@app.get("/logged_out/") +@app.get("/s/") +@app.get("/logged_out/s/") @limiter.limit("3/second;30/minute;400/hour;2000/day") @auth_desired -def front_all(v, hole=None): - if hole and hole not in holes: hole = None +def front_all(v, sub=None): + if sub and sub not in subs: sub = None if g.webview and not session.get("session_id"): session.permanent = True session["session_id"] = secrets.token_hex(49) @@ -165,7 +165,7 @@ def front_all(v, hole=None): filter_words=v.filter_words if v else [], gt=int(request.values.get("utc_greater_than", 0)), lt=int(request.values.get("utc_less_than", 0)), - hole=hole + sub=sub ) posts = get_posts(ids, v=v) @@ -247,17 +247,17 @@ def front_all(v, hole=None): g.db.commit() if request.headers.get("Authorization"): return {"data": [x.json for x in posts], "next_exists": next_exists} - return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page, ccmode=ccmode, hole=hole) + return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page, ccmode=ccmode, sub=sub) @cache.memoize(timeout=86400) -def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false", filter_words='', gt=None, lt=None, hole=None): +def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false", filter_words='', gt=None, lt=None, sub=None): posts = g.db.query(Submission) - if hole: posts = posts.filter_by(hole=hole) - else: posts = posts.filter_by(hole=None) + if sub: posts = posts.filter_by(sub=sub) + else: posts = posts.filter_by(sub=None) if t == 'all': cutoff = 0 else: @@ -327,8 +327,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false" if (sort == "hot" or (v and v.id == Q_ID)) and page == 1 and ccmode == "false": pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False) - if hole: pins = pins.filter_by(hole=hole) - else: pins = pins.filter_by(hole=None) + if sub: pins = pins.filter_by(sub=sub) + else: pins = pins.filter_by(sub=None) if v and v.admin_level == 0: blocking = [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=v.id).all()] blocked = [x[0] for x in g.db.query(UserBlock.user_id).filter_by(target_id=v.id).all()] diff --git a/files/routes/posts.py b/files/routes/posts.py index d118bde10..685ed2e88 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -88,18 +88,22 @@ def publish(pid, v): return {"message": "Post published!"} @app.get("/submit") -@app.get("/submit/") +@app.get("/s//submit") @auth_required -def submit_get(v, hole=None): - if hole and hole not in holes: hole = None - return render_template("submit.html", v=v, hole=hole) +def submit_get(v, sub=None): + if sub and sub not in subs: sub = None + return render_template("submit.html", v=v, sub=sub) @app.get("/post/") @app.get("/post//") @app.get("/logged_out/post/") @app.get("/logged_out/post//") +@app.get("/s//post/") +@app.get("/s//post//") +@app.get("/logged_out/s//post/") +@app.get("/logged_out/s//post//") @auth_desired -def post_id(pid, anything=None, v=None): +def post_id(pid, anything=None, v=None, sub=None): if not v and not request.path.startswith('/logged_out') and not request.headers.get("Authorization"): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") @@ -244,7 +248,7 @@ def post_id(pid, anything=None, v=None): else: if post.is_banned and not (v and (v.admin_level > 1 or post.author_id == v.id)): template = "submission_banned.html" else: template = "submission.html" - return render_template(template, v=v, p=post, ids=list(ids), sort=sort, render_replies=True, offset=offset, hole=post.hole) + return render_template(template, v=v, p=post, ids=list(ids), sort=sort, render_replies=True, offset=offset, sub=post.sub) @app.post("/viewmore///") @limiter.limit("1/second;30/minute;200/hour;1000/day") @@ -752,11 +756,11 @@ def thumbnail_thread(pid): @app.post("/submit") -@app.post("/submit/") +@app.post("/s//submit") @limiter.limit("1/second;6/minute;200/hour;1000/day") @auth_required -def submit_post(v, hole=None): - if hole and hole not in holes: hole = None +def submit_post(v, sub=None): + if sub and sub not in subs: sub = None if v.is_suspended: return {"error": "You can't perform this action while banned."}, 403 if v and v.patron: @@ -1010,7 +1014,7 @@ def submit_post(v, hole=None): title=title[:500], title_html=title_html, created_utc=int(time.time()), - hole=hole + sub=sub ) g.db.add(new_post) @@ -1239,7 +1243,7 @@ def submit_post(v, hole=None): if 'megathread' in new_post.title.lower(): sort = 'new' else: sort = v.defaultsortingcomments if len(body_html) < 40000: new_post.replies = [c] - return render_template('submission.html', v=v, p=new_post, sort=sort, render_replies=True, offset=0, success=True, hole=new_post.hole) + return render_template('submission.html', v=v, p=new_post, sort=sort, render_replies=True, offset=0, success=True, sub=new_post.sub) @app.post("/delete_post/") diff --git a/files/templates/header.html b/files/templates/header.html index d94a3b14b..8e256421b 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -35,7 +35,7 @@ {% endif %} {% if v %} - + {% else %} {% endif %} @@ -77,7 +77,7 @@ {% endif %}