remotes/1693045480750635534/spooky-22
Aevann1 2022-02-04 20:35:39 +02:00
parent d2a2925de0
commit d301d733c5
12 changed files with 49 additions and 40 deletions

View File

@ -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"

View File

@ -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" <i>({self.note})</i>"

View File

@ -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

View File

@ -560,4 +560,4 @@ FORTUNE_REPLIES = ('<b style="color:#6023f8">Your fortune: Allah Wills It</b>','
no_pass_phrase = """<p>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 <a href="/shop">shop</a>) \n\n<em>This is an automated message; if you need help, you can message us <a href="/contact">here</a>.</em></p>"""
holes = ('2balkan4u','2middleeast4u')
subs = ('2balkan4u','2middleeast4u')

View File

@ -26,8 +26,12 @@ CF_HEADERS = {"Authorization": f"Bearer {CF_KEY}", "Content-Type": "application/
@app.get("/post/<pid>/<anything>/<cid>")
@app.get("/logged_out/comment/<cid>")
@app.get("/logged_out/post/<pid>/<anything>/<cid>")
@app.get("/s/<sub>/comment/<cid>")
@app.get("/s/<sub>/post/<pid>/<anything>/<cid>")
@app.get("/logged_out/s/<sub>/comment/<cid>")
@app.get("/logged_out/s/<sub>/post/<pid>/<anything>/<cid>")
@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")

View File

@ -128,12 +128,12 @@ def notifications(v):
@app.get("/")
@app.get("/logged_out")
@app.get("/<hole>")
@app.get("/logged_out/<hole>")
@app.get("/s/<sub>")
@app.get("/logged_out/s/<sub>")
@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()]

View File

@ -88,18 +88,22 @@ def publish(pid, v):
return {"message": "Post published!"}
@app.get("/submit")
@app.get("/submit/<hole>")
@app.get("/s/<sub>/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/<pid>")
@app.get("/post/<pid>/<anything>")
@app.get("/logged_out/post/<pid>")
@app.get("/logged_out/post/<pid>/<anything>")
@app.get("/s/<sub>/post/<pid>")
@app.get("/s/<sub>/post/<pid>/<anything>")
@app.get("/logged_out/s/<sub>/post/<pid>")
@app.get("/logged_out/s/<sub>/post/<pid>/<anything>")
@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/<pid>/<sort>/<offset>")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@ -752,11 +756,11 @@ def thumbnail_thread(pid):
@app.post("/submit")
@app.post("/submit/<hole>")
@app.post("/s/<sub>/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/<pid>")

View File

@ -35,7 +35,7 @@
<a class="mobile-nav-icon d-md-none" href="/admin"><i class="fas fa-crown align-middle text-gray-500 black"></i></a>
{% endif %}
{% if v %}
<a class="mobile-nav-icon d-md-none" href="/submit{% if hole %}/{{hole}}{% endif %}"><i class="fas fa-feather-alt align-middle text-gray-500 black"></i></a>
<a class="mobile-nav-icon d-md-none" href="{% if sub %}/s/{{sub}}{% endif %}/submit"><i class="fas fa-feather-alt align-middle text-gray-500 black"></i></a>
{% else %}
<a class="mobile-nav-icon d-md-none" href="/login"><i class="fas fa-feather-alt align-middle text-gray-500 black"></i></a>
{% endif %}
@ -77,7 +77,7 @@
{% endif %}
<li class="nav-item d-flex align-items-center justify-content-center text-center mx-1">
<a class="nav-link" href="/submit{% if hole %}/{{hole}}{% endif %}" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-original-title="Create post"><i class="fas fa-feather-alt"></i></a>
<a class="nav-link" href="{% if sub %}/s/{{sub}}{% endif %}/submit" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-original-title="Create post"><i class="fas fa-feather-alt"></i></a>
</li>
<li class="nav-item d-flex align-items-center justify-content-center text-center mx-1">

View File

@ -114,7 +114,7 @@
</div>
<div class="card-body">
{% if v %}
<a href="/submit{% if hole %}/{{hole}}{% endif %}">
<a href="{% if sub %}/s/{{sub}}{% endif %}/submit">
<input autocomplete="off" type="text" class="form-control"
aria-label="Username"
aria-describedby="basic-addon1">

View File

@ -550,7 +550,7 @@
</span>
<h2 class="h5">You haven't {% if "saved" in request.full_path %}saved{% else %}made{% endif %} a post yet</h2>
<p class="text-muted mb-md-5">Your {% if "saved" in request.full_path %}saved posts{% else %}posting history{% endif %} will show here.</p>
{% if "saved" not in request.full_path %}<a href="/submit{% if hole %}/{{hole}}{% endif %}" class="btn btn-primary">Create a post</a>{% endif %}
{% if "saved" not in request.full_path %}<a href="{% if sub %}/s/{{sub}}{% endif %}/submit" class="btn btn-primary">Create a post</a>{% endif %}
</div>
</div>
</div>

View File

@ -63,7 +63,7 @@
<div class="submit-grid-view">
<form id="submitform" action="/submit{% if hole %}/{{hole}}{% endif %}" method="post" enctype="multipart/form-data" style="grid-column: 2">
<form id="submitform" action="{% if sub %}/s/{{sub}}{% endif %}/submit" method="post" enctype="multipart/form-data" style="grid-column: 2">
<div class="container">

View File

@ -628,7 +628,7 @@ CREATE TABLE public.submissions (
flair character varying(350),
stickied_utc integer,
ghost boolean,
hole character varying(20)
sub character varying(20)
);