diff --git a/files/classes/submission.py b/files/classes/submission.py index 668b9cd7af..8932fa57a1 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -50,6 +50,7 @@ class Submission(Base): url = Column(String) body = Column(String) body_html = Column(String) + flair = Column(String) ban_reason = Column(String) embed_url = Column(String) @@ -213,11 +214,11 @@ class Submission(Base): @property @lazy def thumb_url(self): - if self.over_18: return f"http://{site}/assets/images/nsfw.webp" - elif not self.url: return f"http://{site}/assets/images/{site_name}/default_text.webp" + if self.over_18: return f"https://{site}/assets/images/nsfw.webp" + elif not self.url: return f"https://{site}/assets/images/{site_name}/default_text.webp" elif self.thumburl: return self.thumburl - elif "youtu.be" in self.domain or "youtube.com" == self.domain: return f"http://{site}/assets/images/default_thumb_yt.webp" - else: return f"http://{site}/assets/images/default_thumb_link.webp" + elif "youtu.be" in self.domain or "youtube.com" == self.domain: return f"https://{site}/assets/images/default_thumb_yt.webp" + else: return f"https://{site}/assets/images/default_thumb_link.webp" @property @lazy @@ -336,6 +337,7 @@ class Submission(Base): rand = random.randint(0, maxupvotes) if self.upvotes < rand: amount = random.randint(0, 3) + self.views += amount*random.randint(3, 5) self.upvotes += amount g.db.add(self) self.author.coins += amount diff --git a/files/classes/user.py b/files/classes/user.py index 67d3aa3920..d629100b14 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -411,15 +411,15 @@ class User(Base): @lazy def banner_url(self): if self.bannerurl: return self.bannerurl - else: return f"http://{site}/assets/images/{site_name}/preview.webp?v=3" + else: return f"https://{site}/assets/images/{site_name}/preview.webp?v=3" @property @lazy def profile_url(self): - if self.agendaposter: return f"http://{site}/assets/images/defaultpictures/agendaposter/{random.randint(1, 50)}.webp?v=1" + if self.agendaposter: return f"https://{site}/assets/images/defaultpictures/agendaposter/{random.randint(1, 50)}.webp?v=1" if self.profileurl: return self.profileurl - if "rama" in site: return f"http://{site}/assets/images/defaultpictures/{random.randint(1, 150)}.webp?v=1" - return f"http://{site}/assets/images/default-profile-pic.webp" + if "rama" in site: return f"https://{site}/assets/images/defaultpictures/{random.randint(1, 150)}.webp?v=1" + return f"https://{site}/assets/images/default-profile-pic.webp" @property @lazy diff --git a/files/helpers/const.py b/files/helpers/const.py index 615e1e0334..5c82540b8e 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -148,6 +148,7 @@ if SITE == 'rdrama.net': LLM_ID = 253 DAD_ID = 2513 MOM_ID = 4588 + BUG_THREAD = 18459 elif SITE == "pcmemes.net": BASEDBOT_ID = 800 KIPPY_ID = 1592 @@ -168,6 +169,7 @@ elif SITE == "pcmemes.net": LLM_ID = 0 DAD_ID = 0 MOM_ID = 0 + BUG_THREAD = 4103 else: BASEDBOT_ID = 0 KIPPY_ID = 0 @@ -188,6 +190,7 @@ else: LLM_ID = 0 DAD_ID = 0 MOM_ID = 0 + BUG_THREAD = 0 PUSHER_INSTANCE_ID = '02ddcc80-b8db-42be-9022-44c546b4dce6' PUSHER_KEY = environ.get("PUSHER_KEY", "").strip() diff --git a/files/helpers/get.py b/files/helpers/get.py index 9df2bcb5f3..6a430506b6 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -216,7 +216,7 @@ def get_comment(i, v=None, graceful=False): return comment -def get_comments(cids, v=None, load_parent=False): +def get_comments(cids, v=None, load_parent=False, shadowbanned=False): if not cids: return [] @@ -235,8 +235,8 @@ def get_comments(cids, v=None, load_parent=False): blocking.c.id, blocked.c.id, ).filter(Comment.id.in_(cids)) - - if not (v and v.shadowbanned) and not (v and v.admin_level > 1): + + if not shadowbanned and not v.shadowbanned and v.admin_level < 2: comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None) comments = comments.join( diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 4d8df5f94e..5392337561 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -182,7 +182,7 @@ def sanitize(sanitized, noimages=False): remoji = emoji if path.isfile(f'./files/assets/images/emojis/{remoji}.webp'): - new = re.sub(f'(?', new) + new = re.sub(f'(?', new) if remoji in session["favorite_emojis"]: session["favorite_emojis"][remoji] += 1 else: session["favorite_emojis"][remoji] = 1 @@ -195,13 +195,13 @@ def sanitize(sanitized, noimages=False): if emoji.startswith("!"): emoji = emoji[1:] if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'(?', sanitized) + sanitized = re.sub(f'(?', sanitized) if emoji in session["favorite_emojis"]: session["favorite_emojis"][emoji] += 1 else: session["favorite_emojis"][emoji] = 1 elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'(?', sanitized) + sanitized = re.sub(f'(?', sanitized) if emoji in session["favorite_emojis"]: session["favorite_emojis"][emoji] += 1 else: session["favorite_emojis"][emoji] = 1 @@ -265,10 +265,10 @@ def filter_title(title): if emoji.startswith("!"): emoji = emoji[1:] if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title) + title = re.sub(f'(?', title) elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title) + title = re.sub(f'(?', title) if len(title) > 1500: abort(400) else: return title \ No newline at end of file diff --git a/files/routes/comments.py b/files/routes/comments.py index 71867fbf1f..f51ec5fc35 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -565,7 +565,7 @@ def api_comment(v): 'notification': { 'title': f'New reply by @{v.username}', 'body': c.body, - 'deep_link': f'http://{site}/comment/{c.id}?context=9&read=true#context', + 'deep_link': f'https://{site}/comment/{c.id}?context=9&read=true#context', }, }, }, diff --git a/files/routes/feeds.py b/files/routes/feeds.py index 50b49c9803..f2ed56b315 100644 --- a/files/routes/feeds.py +++ b/files/routes/feeds.py @@ -51,7 +51,7 @@ def feeds_user(sort='hot', t='all'): with tag("name"): text(post.author.username) with tag("uri"): - text(f'http://{site}/@{post.author.username}') + text(f'https://{site}/@{post.author.username}') doc.stag("link", href=full_link(post.permalink)) diff --git a/files/routes/front.py b/files/routes/front.py index 21bbf555f4..2bd50296ea 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -367,7 +367,7 @@ def random_post(v): return redirect(f"/post/{post.id}") @cache.memoize(timeout=86400) -def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all"): +def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", shadowbanned=False): posts = g.db.query(Submission) cc_idlist = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()] @@ -415,6 +415,7 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all"): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) + if shadowbanned: comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned != None) comments = comments.offset(25 * (page - 1)).limit(26).all() return [x[0] for x in comments] @@ -428,17 +429,20 @@ def all_comments(v): sort=request.values.get("sort", "new") t=request.values.get("t", defaulttimefilter) + if request.values.get("shadowbanned") and v and v.admin_level > 1: shadowbanned = True + else: shadowbanned = False + idlist = comment_idlist(v=v, page=page, sort=sort, t=t, - ) - - comments = get_comments(idlist, v=v) + shadowbanned=shadowbanned + ) + comments = get_comments(idlist, v=v, shadowbanned=shadowbanned) next_exists = len(idlist) > 25 idlist = idlist[:25] if request.headers.get("Authorization"): return {"data": [x.json for x in comments]} - else: return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists) + else: return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists, shadowbanned=shadowbanned) diff --git a/files/routes/posts.py b/files/routes/posts.py index ead14c3dbb..d08357e951 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -62,12 +62,12 @@ def publish(pid, v): user = g.db.query(User).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id) - for x in notify_users: send_notification(x, f"@{v.username} has mentioned you: http://{site}{post.permalink}") + for x in notify_users: send_notification(x, f"@{v.username} has mentioned you: https://{site}{post.permalink}") for follow in v.followers: user = get_account(follow.user_id) if post.club and not user.club_allowed: continue - send_notification(user.id, f"@{v.username} has made a new post: [{post.title}](http://{site}{post.permalink})", True) + send_notification(user.id, f"@{v.username} has made a new post: [{post.title}](https://{site}{post.permalink})", True) cache.delete_memoized(frontlist) @@ -169,9 +169,6 @@ def post_id(pid, anything=None, v=None): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - offset = int(request.values.get("offset", 0)) - if offset: comments = comments.offset(offset) - comments = [c[0] for c in comments.all()] else: pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.is_pinned != None).all() @@ -189,27 +186,28 @@ def post_id(pid, anything=None, v=None): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - offset = 0 - comments = comments.all() - comments2 = [] - count = 0 - if post.created_utc > 1638672040: - for comment in comments: - comments2.append(comment) - count += g.db.query(Comment.id).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1 - offset += 1 - if count > 50: break - else: - for comment in comments: - comments2.append(comment) - count += g.db.query(Comment.id).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1 - offset += 1 - if count > 10: break + offset = 0 - if len(comments) == len(comments2): offset = None - comments = comments2 + if len(comments) > 60: + comments2 = [] + count = 0 + if post.created_utc > 1638672040: + for comment in comments: + comments2.append(comment) + count += g.db.query(Comment.id).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1 + offset += 1 + if count > 50: break + else: + for comment in comments: + comments2.append(comment) + count += g.db.query(Comment.id).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1 + offset += 1 + if count > 10: break + + if len(comments) == len(comments2): offset = None + comments = comments2 post.replies = pinned + comments @@ -231,6 +229,7 @@ def post_id(pid, anything=None, v=None): @limiter.limit("1/second") @auth_desired def viewmore(v, pid, sort, offset): + offset = int(offset) if v: votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() @@ -285,7 +284,7 @@ def viewmore(v, pid, sort, offset): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - if offset: comments = comments.offset(int(offset)) + comments = comments.offset(offset) comments = [c[0] for c in comments.all()] else: @@ -302,11 +301,32 @@ def viewmore(v, pid, sort, offset): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - if offset: comments = comments.offset(int(offset)) - + comments = comments.offset(offset) + comments = comments.all() - return render_template("comments.html", v=v, comments=comments, render_replies=True) + if len(comments) > 60: + comments2 = [] + count = 0 + post = get_post(pid, v=v) + if post.created_utc > 1638672040: + for comment in comments: + comments2.append(comment) + count += g.db.query(Comment.id).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1 + offset += 1 + if count > 50: break + else: + for comment in comments: + comments2.append(comment) + count += g.db.query(Comment.id).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1 + offset += 1 + if count > 10: break + + if len(comments) == len(comments2): offset = None + comments = comments2 + else: offset = None + + return render_template("comments.html", v=v, comments=comments, render_replies=True, pid=pid, sort=sort, offset=offset) @app.post("/edit_post/") @@ -483,7 +503,7 @@ def edit_post(pid, v): user = g.db.query(User).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id) - message = f"@{v.username} has mentioned you: http://{site}{p.permalink}" + message = f"@{v.username} has mentioned you: https://{site}{p.permalink}" for x in notify_users: send_notification(x, message) @@ -526,8 +546,8 @@ def thumbnail_thread(pid): if fragment_url.startswith("https://"): return fragment_url - elif fragment_url.startswith("http://"): - return f"https://{fragment_url.split('http://')[1]}" + elif fragment_url.startswith("https://"): + return f"https://{fragment_url.split('https://')[1]}" elif fragment_url.startswith('//'): return f"https:{fragment_url}" elif fragment_url.startswith('/'): @@ -970,12 +990,12 @@ def submit_post(v): user = g.db.query(User).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id) - for x in notify_users: send_notification(x, f"@{v.username} has mentioned you: http://{site}{new_post.permalink}") + for x in notify_users: send_notification(x, f"@{v.username} has mentioned you: https://{site}{new_post.permalink}") for follow in v.followers: user = get_account(follow.user_id) if new_post.club and not user.club_allowed: continue - send_notification(user.id, f"@{v.username} has made a new post: [{title}](http://{site}{new_post.permalink})", True) + send_notification(user.id, f"@{v.username} has made a new post: [{title}](https://{site}{new_post.permalink})", True) g.db.add(new_post) g.db.flush() @@ -1121,7 +1141,7 @@ def submit_post(v): cache.delete_memoized(frontlist) cache.delete_memoized(User.userpagelisting) if v.admin_level > 1 and ("[changelog]" in new_post.title or "(changelog)" in new_post.title): - send_message(f"http://{site}{new_post.permalink}") + send_message(f"https://{site}{new_post.permalink}") cache.delete_memoized(changeloglist) g.db.commit() diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 4e8cde1876..f38a840222 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -4,48 +4,47 @@ from flask import g from files.__main__ import app, limiter from os import path -@app.post("/flag/post/") +@app.post("/report/post/") @limiter.limit("1/second") -@auth_desired +@auth_required def api_flag_post(pid, v): post = get_post(pid) - if v and not v.shadowbanned: - existing = g.db.query(Flag.id).filter_by(user_id=v.id, post_id=post.id).first() - - if existing: return "", 409 - + if not v.shadowbanned: reason = request.values.get("reason", "").strip()[:100] if "<" in reason: return {"error": f"Reasons can't contain <"} + if not reason.startswith('!'): + existing = g.db.query(Flag.id).filter_by(user_id=v.id, post_id=post.id).first() + if existing: return "", 409 + for i in re.finditer(':(.{1,30}?):', reason): if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.webp'): - reason = reason.replace(f':{i.group(1)}:', f':{i.group(1)}:') + reason = reason.replace(f':{i.group(1)}:', f':{i.group(1)}:') if len(reason) > 350: return {"error": f"Too long."} - flag = Flag(post_id=post.id, - user_id=v.id, - reason=reason, - ) - - - g.db.add(flag) + if reason.startswith('!') and v.admin_level > 1: + post.flair = reason[1:] + g.db.add(post) + else: + flag = Flag(post_id=post.id, user_id=v.id, reason=reason) + g.db.add(flag) g.db.commit() return {"message": "Post reported!"} -@app.post("/flag/comment/") +@app.post("/report/comment/") @limiter.limit("1/second") -@auth_desired +@auth_required def api_flag_comment(cid, v): comment = get_comment(cid) - if v and not v.shadowbanned: + if not v.shadowbanned: existing = g.db.query(CommentFlag.id).filter_by( user_id=v.id, comment_id=comment.id).first() @@ -55,7 +54,7 @@ def api_flag_comment(cid, v): for i in re.finditer(':(.{1,30}?):', reason): if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.webp'): - reason = reason.replace(f':{i.group(1)}:', f':{i.group(1)}:') + reason = reason.replace(f':{i.group(1)}:', f':{i.group(1)}:') if len(reason) > 350: return {"error": f"Too long."} diff --git a/files/routes/static.py b/files/routes/static.py index 476d4ae3bb..6b5f2f4dea 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -231,7 +231,7 @@ def contact(v): @limiter.limit("1/second") @auth_required def submit_contact(v): - message = f'This message has been sent automatically to all admins via http://{site}/contact, user email is "{v.email}"\n\nMessage:\n\n' + request.values.get("message", "") + message = f'This message has been sent automatically to all admins via https://{site}/contact, user email is "{v.email}"\n\nMessage:\n\n' + request.values.get("message", "") send_admin(v.id, message) g.db.commit() return render_template("contact.html", v=v, msg="Your message has been sent.") diff --git a/files/routes/users.py b/files/routes/users.py index 36213e729b..46e5e9a68f 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -383,7 +383,7 @@ def message2(v, username): 'notification': { 'title': f'New message from @{v.username}', 'body': message, - 'deep_link': f'http://{site}/notifications', + 'deep_link': f'https://{site}/notifications', }, }, }, diff --git a/files/templates/authforms.html b/files/templates/authforms.html index ab3848b48d..558c7092cf 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -10,16 +10,16 @@ {% block pagetitle %}{{'SITE_NAME' | app_config}}{% endblock %} - + {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} diff --git a/files/templates/changelog.html b/files/templates/changelog.html index 5d7122a883..0e711b6db5 100644 --- a/files/templates/changelog.html +++ b/files/templates/changelog.html @@ -81,9 +81,6 @@ -{% endblock %} - -{% block pagenav %} {% if listing %}