remove holes (#492)
* remove holes * don't import class that doesn't exist * remove subs in template code * remove subs_created * fix sticky bug * uh... i think this will fix it???? * fix stupid nearly ungrokkable nesting error * ... * .... * .... * *sigh* * .............................i think i got it. * Revert ".............................i think i got it." This reverts commit419a545875
. * Revert "*sigh*" This reverts commitfcfc9d7995
. * Revert "...." This reverts commite200c8f6f0
. * Revert "...." This reverts commit681db8cb02
. * Revert "..." This reverts commitc54372b9ff
. * Revert "fix stupid nearly ungrokkable nesting error" This reverts commite202fd774c
. * Revert "uh... i think this will fix it????" This reverts commite4d9366093
. * readd missing endif * fix email templates. * fix frontpage listing * some minor fixes wrt saving * fix some listing errors * Remove more references to holes system A couple of these came from the merge of #554. A few others were just left in the templates and presumably hard to catch on the first removal pass. * remove unnecessary lazy * Add migration Tested. Very sensitive to order. I wound up borrowing the statement order we used for deleting sub rows on upstream (manually, of course). --------- Co-authored-by: TLSM <duolsm@outlook.com>
This commit is contained in:
parent
1647b4cf20
commit
77af24a5b1
42 changed files with 226 additions and 1260 deletions
|
@ -20,4 +20,3 @@ if FEATURES['AWARDS']:
|
|||
from .volunteer import *
|
||||
if app.debug:
|
||||
from .dev import *
|
||||
# from .subs import *
|
||||
|
|
|
@ -10,10 +10,8 @@ from files.routes.importstar import *
|
|||
|
||||
@app.get("/comment/<cid>")
|
||||
@app.get("/post/<pid>/<anything>/<cid>")
|
||||
# @app.get("/h/<sub>/comment/<cid>")
|
||||
# @app.get("/h/<sub>/post/<pid>/<anything>/<cid>")
|
||||
@auth_desired
|
||||
def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
|
||||
def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
||||
comment = get_comment(cid, v=v)
|
||||
|
||||
if v and request.values.get("read"):
|
||||
|
@ -100,7 +98,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=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, sub=post.subr)
|
||||
return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True)
|
||||
|
||||
@app.post("/comment")
|
||||
@limiter.limit("1/second;20/minute;200/hour;1000/day")
|
||||
|
@ -115,7 +113,6 @@ def api_comment(v):
|
|||
parent = None
|
||||
parent_post = None
|
||||
parent_comment_id = None
|
||||
sub = None
|
||||
|
||||
if parent_fullname.startswith("t2_"):
|
||||
parent = get_post(id, v=v)
|
||||
|
@ -127,8 +124,6 @@ def api_comment(v):
|
|||
else: abort(400)
|
||||
if not parent_post: abort(404) # don't allow sending comments to the ether
|
||||
level = 1 if isinstance(parent, Submission) else parent.level + 1
|
||||
sub = parent_post.sub
|
||||
if sub and v.exiled_from(sub): abort(403, f"You're exiled from /h/{sub}")
|
||||
|
||||
body = sanitize_raw(request.values.get("body"), allow_newlines=True, length_limit=COMMENT_BODY_LENGTH_MAXIMUM)
|
||||
if not body and not request.files.get('file'):
|
||||
|
@ -413,46 +408,6 @@ def unpin_comment(cid, v):
|
|||
return {"message": "Comment unpinned!"}
|
||||
|
||||
|
||||
@app.post("/mod_pin/<cid>")
|
||||
@auth_required
|
||||
def mod_pin(cid, v):
|
||||
|
||||
comment = get_comment(cid, v=v)
|
||||
|
||||
if not comment.is_pinned:
|
||||
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
|
||||
|
||||
comment.is_pinned = v.username + " (Mod)"
|
||||
|
||||
g.db.add(comment)
|
||||
|
||||
if v.id != comment.author_id:
|
||||
message = f"@{v.username} (Mod) has pinned your [comment]({comment.shortlink})!"
|
||||
send_repeatable_notification(comment.author_id, message)
|
||||
|
||||
g.db.commit()
|
||||
return {"message": "Comment pinned!"}
|
||||
|
||||
|
||||
@app.post("/unmod_pin/<cid>")
|
||||
@auth_required
|
||||
def mod_unpin(cid, v):
|
||||
|
||||
comment = get_comment(cid, v=v)
|
||||
|
||||
if comment.is_pinned:
|
||||
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
|
||||
|
||||
comment.is_pinned = None
|
||||
g.db.add(comment)
|
||||
|
||||
if v.id != comment.author_id:
|
||||
message = f"@{v.username} (Mod) has unpinned your [comment]({comment.shortlink})!"
|
||||
send_repeatable_notification(comment.author_id, message)
|
||||
g.db.commit()
|
||||
return {"message": "Comment unpinned!"}
|
||||
|
||||
|
||||
@app.post("/save_comment/<cid>")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
|
|
|
@ -163,15 +163,9 @@ def notifications(v):
|
|||
|
||||
@app.get("/")
|
||||
@app.get("/catalog")
|
||||
# @app.get("/h/<sub>")
|
||||
# @app.get("/s/<sub>")
|
||||
@limiter.limit("3/second;30/minute;1000/hour;5000/day")
|
||||
@auth_desired
|
||||
def front_all(v, sub=None, subdomain=None):
|
||||
if sub: sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
|
||||
if (request.path.startswith('/h/') or request.path.startswith('/s/')) and not sub: abort(404)
|
||||
|
||||
def front_all(v, subdomain=None):
|
||||
if g.webview and not session.get("session_id"):
|
||||
session["session_id"] = secrets.token_hex(49)
|
||||
|
||||
|
@ -205,8 +199,6 @@ def front_all(v, sub=None, subdomain=None):
|
|||
filter_words=v.filter_words if v else [],
|
||||
gt=gt,
|
||||
lt=lt,
|
||||
sub=sub,
|
||||
site=SITE
|
||||
)
|
||||
|
||||
posts = get_posts(ids, v=v, eager=True)
|
||||
|
@ -229,7 +221,7 @@ def front_all(v, sub=None, subdomain=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, sub=sub, home=True)
|
||||
return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page, ccmode=ccmode, home=True)
|
||||
|
||||
|
||||
@app.get("/changelog")
|
||||
|
@ -245,7 +237,6 @@ def changelog(v):
|
|||
page=page,
|
||||
t=t,
|
||||
v=v,
|
||||
site=SITE
|
||||
)
|
||||
|
||||
next_exists = (len(ids) > 25)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import sys
|
||||
import time
|
||||
import urllib.parse
|
||||
from io import BytesIO
|
||||
from os import path
|
||||
from sys import stdout
|
||||
from urllib.parse import ParseResult, urlparse
|
||||
|
||||
import gevent
|
||||
|
@ -12,7 +11,7 @@ from PIL import Image as PILimage
|
|||
from sqlalchemy.orm import Query
|
||||
|
||||
import files.helpers.validators as validators
|
||||
from files.__main__ import app, cache, db_session, limiter
|
||||
from files.__main__ import app, db_session, limiter
|
||||
from files.classes import *
|
||||
from files.helpers.alerts import *
|
||||
from files.helpers.caching import invalidate_cache
|
||||
|
@ -68,23 +67,14 @@ def publish(pid, v):
|
|||
return redirect(post.permalink)
|
||||
|
||||
@app.get("/submit")
|
||||
# @app.get("/h/<sub>/submit")
|
||||
@auth_required
|
||||
def submit_get(v, sub=None):
|
||||
if sub: sub = g.db.query(Sub.name).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
|
||||
if request.path.startswith('/h/') and not sub: abort(404)
|
||||
|
||||
SUBS = [x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()]
|
||||
|
||||
return render_template("submit.html", SUBS=SUBS, v=v, sub=sub)
|
||||
def submit_get(v):
|
||||
return render_template("submit.html", v=v)
|
||||
|
||||
@app.get("/post/<pid>")
|
||||
@app.get("/post/<pid>/<anything>")
|
||||
# @app.get("/h/<sub>/post/<pid>")
|
||||
# @app.get("/h/<sub>/post/<pid>/<anything>")
|
||||
@auth_desired
|
||||
def post_id(pid, anything=None, v=None, sub=None):
|
||||
def post_id(pid, anything=None, v=None):
|
||||
post = get_post(pid, v=v)
|
||||
|
||||
if post.over_18 and not (v and v.over_18) and session.get('over_18', 0) < int(time.time()):
|
||||
|
@ -135,7 +125,7 @@ def post_id(pid, anything=None, v=None, sub=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, sub=post.subr)
|
||||
return render_template(template, v=v, p=post, ids=list(ids), sort=sort, render_replies=True, offset=offset)
|
||||
|
||||
@app.get("/viewmore/<pid>/<sort>/<offset>")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
|
@ -430,7 +420,7 @@ def thumbnail_thread(pid):
|
|||
|
||||
db.commit()
|
||||
db.close()
|
||||
stdout.flush()
|
||||
sys.stdout.flush()
|
||||
return
|
||||
|
||||
|
||||
|
@ -439,7 +429,7 @@ def api_is_repost():
|
|||
url = request.values.get('url')
|
||||
if not url: abort(400)
|
||||
|
||||
url = urllib.parse.unparse(canonicalize_url2(url, httpsify=True))
|
||||
url = canonicalize_url2(url, httpsify=True).geturl()
|
||||
if url.endswith('/'): url = url[:-1]
|
||||
|
||||
search_url = sql_ilike_clean(url)
|
||||
|
@ -536,19 +526,16 @@ def _duplicate_check2(
|
|||
|
||||
|
||||
@app.post("/submit")
|
||||
# @app.post("/h/<sub>/submit")
|
||||
@limiter.limit("1/second;2/minute;10/hour;50/day")
|
||||
@auth_required
|
||||
def submit_post(v, sub=None):
|
||||
def submit_post(v):
|
||||
def error(error):
|
||||
title:str = request.values.get("title", "")
|
||||
body:str = request.values.get("body", "")
|
||||
url:str = request.values.get("url", "")
|
||||
|
||||
if request.headers.get("Authorization") or request.headers.get("xhr"): abort(400, error)
|
||||
|
||||
SUBS = [x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()]
|
||||
return render_template("submit.html", SUBS=SUBS, v=v, error=error, title=title, url=url, body=body), 400
|
||||
return render_template("submit.html", v=v, error=error, title=title, url=url, body=body), 400
|
||||
|
||||
if v.is_suspended: return error("You can't perform this action while banned.")
|
||||
|
||||
|
@ -560,17 +547,6 @@ def submit_post(v, sub=None):
|
|||
except ValueError as e:
|
||||
return error(str(e))
|
||||
|
||||
sub = request.values.get("sub")
|
||||
if sub: sub = sub.replace('/h/','').replace('s/','')
|
||||
|
||||
if sub and sub != 'none':
|
||||
sname = sub.strip().lower()
|
||||
sub = g.db.query(Sub.name).filter_by(name=sname).one_or_none()
|
||||
if not sub: return error(f"/h/{sname} not found!")
|
||||
sub = sub[0]
|
||||
if v.exiled_from(sub): return error(f"You're exiled from /h/{sub}")
|
||||
else: sub = None
|
||||
|
||||
duplicate:Optional[werkzeug.wrappers.Response] = \
|
||||
_duplicate_check(validated_post.repost_search_url)
|
||||
if duplicate: return duplicate
|
||||
|
@ -605,7 +581,6 @@ def submit_post(v, sub=None):
|
|||
embed_url=validated_post.embed_slow,
|
||||
title=validated_post.title,
|
||||
title_html=validated_post.title_html,
|
||||
sub=sub,
|
||||
ghost=False,
|
||||
filter_state='filtered' if v.admin_level == 0 and app.config['SETTINGS']['FilterNewPosts'] else 'normal',
|
||||
thumburl=validated_post.thumburl
|
||||
|
@ -624,7 +599,7 @@ def submit_post(v, sub=None):
|
|||
post.voted = 1
|
||||
if 'megathread' in post.title.lower(): sort = 'new'
|
||||
else: sort = v.defaultsortingcomments
|
||||
return render_template('submission.html', v=v, p=post, sort=sort, render_replies=True, offset=0, success=True, sub=post.subr)
|
||||
return render_template('submission.html', v=v, p=post, sort=sort, render_replies=True, offset=0, success=True)
|
||||
|
||||
|
||||
@app.post("/delete_post/<pid>")
|
||||
|
@ -667,7 +642,6 @@ def undelete_post_pid(pid, v):
|
|||
@app.post("/toggle_comment_nsfw/<cid>")
|
||||
@auth_required
|
||||
def toggle_comment_nsfw(cid, v):
|
||||
|
||||
comment = g.db.query(Comment).filter_by(id=cid).one_or_none()
|
||||
if comment.author_id != v.id and not v.admin_level > 1: abort(403)
|
||||
comment.over_18 = not comment.over_18
|
||||
|
@ -681,7 +655,6 @@ def toggle_comment_nsfw(cid, v):
|
|||
@app.post("/toggle_post_nsfw/<pid>")
|
||||
@auth_required
|
||||
def toggle_post_nsfw(pid, v):
|
||||
|
||||
post = get_post(pid)
|
||||
|
||||
if post.author_id != v.id and not v.admin_level > 1:
|
||||
|
@ -707,7 +680,6 @@ def toggle_post_nsfw(pid, v):
|
|||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
def save_post(pid, v):
|
||||
|
||||
post=get_post(pid)
|
||||
|
||||
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=post.id).one_or_none()
|
||||
|
@ -723,7 +695,6 @@ def save_post(pid, v):
|
|||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
def unsave_post(pid, v):
|
||||
|
||||
post=get_post(pid)
|
||||
|
||||
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=post.id).one_or_none()
|
||||
|
@ -742,7 +713,7 @@ def api_pin_post(post_id, v):
|
|||
post.is_pinned = not post.is_pinned
|
||||
g.db.add(post)
|
||||
|
||||
cache.delete_memoized(User.userpagelisting)
|
||||
invalidate_cache(userpagelisting=True)
|
||||
|
||||
g.db.commit()
|
||||
if post.is_pinned: return {"message": "Post pinned!"}
|
||||
|
|
|
@ -1,387 +0,0 @@
|
|||
from files.__main__ import app, limiter, mail
|
||||
from files.helpers.alerts import *
|
||||
from files.helpers.wrappers import *
|
||||
from files.classes import *
|
||||
from .front import frontlist
|
||||
|
||||
|
||||
|
||||
@app.post("/exile/post/<pid>")
|
||||
@is_not_permabanned
|
||||
def exile_post(v, pid):
|
||||
p = get_post(pid)
|
||||
sub = p.sub
|
||||
if not sub: abort(400)
|
||||
|
||||
if not v.mods(sub): abort(403)
|
||||
|
||||
u = p.author
|
||||
|
||||
if u.mods(sub): abort(403)
|
||||
|
||||
if u.admin_level < 2 and not u.exiled_from(sub):
|
||||
exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id)
|
||||
g.db.add(exile)
|
||||
|
||||
send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{p.title}]({p.shortlink})")
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return {"message": "User exiled successfully!"}
|
||||
|
||||
|
||||
|
||||
@app.post("/exile/comment/<cid>")
|
||||
@is_not_permabanned
|
||||
def exile_comment(v, cid):
|
||||
c = get_comment(cid)
|
||||
sub = c.post.sub
|
||||
if not sub: abort(400)
|
||||
|
||||
if not v.mods(sub): abort(403)
|
||||
|
||||
u = c.author
|
||||
|
||||
if u.mods(sub): abort(403)
|
||||
|
||||
if u.admin_level < 2 and not u.exiled_from(sub):
|
||||
exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id)
|
||||
g.db.add(exile)
|
||||
|
||||
send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{c.permalink}]({c.shortlink})")
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return {"message": "User exiled successfully!"}
|
||||
|
||||
|
||||
@app.post("/h/<sub>/unexile/<uid>")
|
||||
@is_not_permabanned
|
||||
def unexile(v, sub, uid):
|
||||
u = get_account(uid)
|
||||
|
||||
if not v.mods(sub): abort(403)
|
||||
|
||||
if u.exiled_from(sub):
|
||||
exile = g.db.query(Exile).filter_by(user_id=u.id, sub=sub).one_or_none()
|
||||
g.db.delete(exile)
|
||||
|
||||
send_notification(u.id, f"@{v.username} has revoked your exile from /h/{sub}")
|
||||
|
||||
g.db.commit()
|
||||
|
||||
|
||||
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"message": "User unexiled successfully!"}
|
||||
return redirect(f'/h/{sub}/exilees')
|
||||
|
||||
@app.post("/h/<sub>/block")
|
||||
@auth_required
|
||||
def block_sub(v, sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
sub = sub.name
|
||||
|
||||
if v.mods(sub): abort(409, "You can't block subs you mod!")
|
||||
|
||||
existing = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub).one_or_none()
|
||||
|
||||
if not existing:
|
||||
block = SubBlock(user_id=v.id, sub=sub)
|
||||
g.db.add(block)
|
||||
g.db.commit()
|
||||
cache.delete_memoized(frontlist)
|
||||
|
||||
return {"message": "Sub blocked successfully!"}
|
||||
|
||||
|
||||
@app.post("/h/<sub>/unblock")
|
||||
@auth_required
|
||||
def unblock_sub(v, sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
sub = sub.name
|
||||
|
||||
block = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub).one_or_none()
|
||||
|
||||
if block:
|
||||
g.db.delete(block)
|
||||
g.db.commit()
|
||||
cache.delete_memoized(frontlist)
|
||||
|
||||
return {"message": "Sub unblocked successfully!"}
|
||||
|
||||
@app.get("/h/<sub>/mods")
|
||||
@auth_required
|
||||
def mods(v, sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
|
||||
users = g.db.query(User, Mod).join(Mod, Mod.user_id==User.id).filter_by(sub=sub.name).order_by(Mod.created_utc).all()
|
||||
|
||||
return render_template("sub/mods.html", v=v, sub=sub, users=users)
|
||||
|
||||
|
||||
@app.get("/h/<sub>/exilees")
|
||||
@auth_required
|
||||
def exilees(v, sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
|
||||
users = g.db.query(User, Exile).join(Exile, Exile.user_id==User.id).filter_by(sub=sub.name).all()
|
||||
|
||||
return render_template("sub/exilees.html", v=v, sub=sub, users=users)
|
||||
|
||||
|
||||
@app.get("/h/<sub>/blockers")
|
||||
@auth_required
|
||||
def blockers(v, sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
|
||||
users = g.db.query(User).join(SubBlock, SubBlock.user_id==User.id).filter_by(sub=sub.name).all()
|
||||
|
||||
return render_template("sub/blockers.html", v=v, sub=sub, users=users)
|
||||
|
||||
|
||||
|
||||
@app.post("/h/<sub>/add_mod")
|
||||
@limiter.limit("1/second;5/day")
|
||||
@is_not_permabanned
|
||||
def add_mod(v, sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
sub = sub.name
|
||||
|
||||
if not v.mods(sub): abort(403)
|
||||
|
||||
user = request.values.get('user')
|
||||
|
||||
if not user: abort(400)
|
||||
|
||||
user = get_user(user)
|
||||
|
||||
existing = g.db.query(Mod).filter_by(user_id=user.id, sub=sub).one_or_none()
|
||||
|
||||
if not existing:
|
||||
mod = Mod(user_id=user.id, sub=sub)
|
||||
g.db.add(mod)
|
||||
|
||||
if v.id != user.id:
|
||||
send_repeatable_notification(user.id, f"@{v.username} has added you as a mod to /h/{sub}")
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return redirect(f'/h/{sub}/mods')
|
||||
|
||||
|
||||
@app.post("/h/<sub>/remove_mod")
|
||||
@is_not_permabanned
|
||||
def remove_mod(v, sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
sub = sub.name
|
||||
|
||||
if not v.mods(sub): abort(403)
|
||||
|
||||
uid = request.values.get('uid')
|
||||
|
||||
if not uid: abort(400)
|
||||
|
||||
try: uid = int(uid)
|
||||
except: abort(400)
|
||||
|
||||
user = g.db.query(User).filter_by(id=uid).one_or_none()
|
||||
|
||||
if not user: abort(404)
|
||||
|
||||
mod = g.db.query(Mod).filter_by(user_id=user.id, sub=sub).one_or_none()
|
||||
if not mod: abort(400)
|
||||
|
||||
if not (v.id == user.id or v.mod_date(sub) and v.mod_date(sub) < mod.created_utc): abort(403)
|
||||
|
||||
g.db.delete(mod)
|
||||
|
||||
if v.id != user.id:
|
||||
send_repeatable_notification(user.id, f"@{v.username} has removed you as a mod from /h/{sub}")
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return redirect(f'/h/{sub}/mods')
|
||||
|
||||
@app.get("/create_sub")
|
||||
@is_not_permabanned
|
||||
def create_sub(v):
|
||||
num = v.subs_created + 1
|
||||
for a in v.alts:
|
||||
num += a.subs_created
|
||||
cost = num * 100
|
||||
|
||||
return render_template("sub/create_sub.html", v=v, cost=cost)
|
||||
|
||||
|
||||
@app.post("/create_sub")
|
||||
@is_not_permabanned
|
||||
def create_sub2(v):
|
||||
name = request.values.get('name')
|
||||
if not name: abort(400)
|
||||
name = name.strip().lower()
|
||||
|
||||
num = v.subs_created + 1
|
||||
for a in v.alts:
|
||||
num += a.subs_created
|
||||
cost = num * 100
|
||||
|
||||
if not valid_sub_regex.fullmatch(name):
|
||||
return render_template("sub/create_sub.html", v=v, cost=cost, error="Sub name not allowed."), 400
|
||||
|
||||
sub = g.db.query(Sub).filter_by(name=name).one_or_none()
|
||||
if not sub:
|
||||
if v.coins < cost:
|
||||
return render_template("sub/create_sub.html", v=v, cost=cost, error="You don't have enough coins!"), 403
|
||||
|
||||
v.coins -= cost
|
||||
|
||||
v.subs_created += 1
|
||||
g.db.add(v)
|
||||
|
||||
sub = Sub(name=name)
|
||||
g.db.add(sub)
|
||||
g.db.flush()
|
||||
mod = Mod(user_id=v.id, sub=sub.name)
|
||||
g.db.add(mod)
|
||||
g.db.commit()
|
||||
|
||||
return redirect(f'/h/{sub.name}')
|
||||
|
||||
@app.post("/kick/<pid>")
|
||||
@is_not_permabanned
|
||||
def kick(v, pid):
|
||||
post = get_post(pid)
|
||||
|
||||
if not post.sub: abort(403)
|
||||
if not v.mods(post.sub): abort(403)
|
||||
|
||||
post.sub = None
|
||||
g.db.add(post)
|
||||
g.db.commit()
|
||||
|
||||
cache.delete_memoized(frontlist)
|
||||
|
||||
return {"message": "Post kicked successfully!"}
|
||||
|
||||
|
||||
@app.get('/h/<sub>/settings')
|
||||
@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)
|
||||
|
||||
if not v.mods(sub.name): abort(403)
|
||||
|
||||
return render_template('sub/settings.html', v=v, sidebar=sub.sidebar, sub=sub)
|
||||
|
||||
|
||||
@app.post('/h/<sub>/sidebar')
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@is_not_permabanned
|
||||
def post_sub_sidebar(v, sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
|
||||
if not v.mods(sub.name): abort(403)
|
||||
|
||||
sub.sidebar = request.values.get('sidebar', '').strip()[:500]
|
||||
sub.sidebar_html = sanitize(sub.sidebar)
|
||||
if len(sub.sidebar_html) > 1000: return "Sidebar is too big!"
|
||||
|
||||
g.db.add(sub)
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return redirect(f'/h/{sub.name}/settings')
|
||||
|
||||
|
||||
@app.post('/h/<sub>/css')
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@is_not_permabanned
|
||||
def post_sub_css(v, sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
|
||||
if not v.mods(sub.name): abort(403)
|
||||
|
||||
sub.css = request.values.get('css', '').strip()
|
||||
g.db.add(sub)
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return redirect(f'/h/{sub.name}/settings')
|
||||
|
||||
|
||||
@app.get("/h/<sub>/css")
|
||||
def get_sub_css(sub):
|
||||
sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
resp=make_response(sub.css or "")
|
||||
resp.headers.add("Content-Type", "text/css")
|
||||
return resp
|
||||
|
||||
|
||||
@app.post("/h/<sub>/banner")
|
||||
@limiter.limit("1/second;10/day")
|
||||
@is_not_permabanned
|
||||
def sub_banner(v, sub):
|
||||
if request.headers.get("cf-ipcountry") == "T1": abort(403, "Image uploads are not allowed through TOR.")
|
||||
|
||||
sub = g.db.query(Sub).filter_by(name=sub.lower().strip()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
|
||||
if not v.mods(sub.name): abort(403)
|
||||
|
||||
file = request.files["banner"]
|
||||
|
||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||
file.save(name)
|
||||
bannerurl = process_image(name)
|
||||
|
||||
if bannerurl:
|
||||
if sub.bannerurl and '/images/' in sub.bannerurl:
|
||||
fpath = '/images/' + sub.bannerurl.split('/images/')[1]
|
||||
if path.isfile(fpath): os.remove(fpath)
|
||||
sub.bannerurl = bannerurl
|
||||
g.db.add(sub)
|
||||
g.db.commit()
|
||||
|
||||
return redirect(f'/h/{sub.name}/settings')
|
||||
|
||||
@app.post("/h/<sub>/sidebar_image")
|
||||
@limiter.limit("1/second;10/day")
|
||||
@is_not_permabanned
|
||||
def sub_sidebar(v, sub):
|
||||
if request.headers.get("cf-ipcountry") == "T1": abort(403, "Image uploads are not allowed through TOR.")
|
||||
|
||||
sub = g.db.query(Sub).filter_by(name=sub.lower().strip()).one_or_none()
|
||||
if not sub: abort(404)
|
||||
|
||||
if not v.mods(sub.name): abort(403)
|
||||
|
||||
file = request.files["sidebar"]
|
||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||
file.save(name)
|
||||
sidebarurl = process_image(name)
|
||||
|
||||
if sidebarurl:
|
||||
if sub.sidebarurl and '/images/' in sub.sidebarurl:
|
||||
fpath = '/images/' + sub.sidebarurl.split('/images/')[1]
|
||||
if path.isfile(fpath): os.remove(fpath)
|
||||
sub.sidebarurl = sidebarurl
|
||||
g.db.add(sub)
|
||||
g.db.commit()
|
||||
|
||||
return redirect(f'/h/{sub.name}/settings')
|
||||
|
||||
@app.get("/holes")
|
||||
@auth_desired
|
||||
def subs(v):
|
||||
subs = g.db.query(Sub, func.count(Submission.sub)).outerjoin(Submission, Sub.name == Submission.sub).group_by(Sub.name).order_by(func.count(Submission.sub).desc()).all()
|
||||
return render_template('sub/subs.html', v=v, subs=subs)
|
|
@ -681,7 +681,7 @@ def u_username(username, v=None):
|
|||
try: page = max(int(request.values.get("page", 1)), 1)
|
||||
except: page = 1
|
||||
|
||||
ids = listings.userpagelisting(u, site=SITE, v=v, page=page, sort=sort, t=t)
|
||||
ids = listings.userpagelisting(u, v=v, page=page, sort=sort, t=t)
|
||||
|
||||
next_exists = (len(ids) > 25)
|
||||
ids = ids[:25]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue