From 88dc847861f0b9bdec94a5e634d65200e4147c6e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 24 Dec 2021 05:59:07 +0200 Subject: [PATCH] fds --- files/__main__.py | 2 +- files/routes/admin.py | 4 ++-- files/routes/front.py | 12 +++++++++++- files/routes/posts.py | 6 ++++++ files/routes/votes.py | 10 ---------- files/templates/submission.html | 2 +- files/templates/submission_listing.html | 2 +- seed-db.sql | 3 +-- 8 files changed, 23 insertions(+), 18 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index e90ac9eb7..550bfb785 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -57,7 +57,7 @@ app.config["RATELIMIT_ENABLED"] = True app.config["RATELIMIT_DEFAULTS_DEDUCT_WHEN"]=lambda:True app.config["RATELIMIT_DEFAULTS_EXEMPT_WHEN"]=lambda:False app.config["RATELIMIT_HEADERS_ENABLED"]=True -app.config["CACHE_TYPE"] = "redis" +app.config["CACHE_TYPE"] = "filesystem" app.config["CACHE_DIR"] = "cache" app.config["RATELIMIT_STORAGE_URL"] = environ.get("REDIS_URL", "redis://localhost") app.config['MAIL_SERVER'] = 'smtp.gmail.com' diff --git a/files/routes/admin.py b/files/routes/admin.py index 1ca388280..3e5d6bf67 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1029,14 +1029,14 @@ def api_sticky_post(post_id, v): post = g.db.query(Submission).filter_by(id=post_id).first() if post: if post.stickied: - if post.stickied.startswith("t:"): return {"error": "Can't unpin temporary pins!"}, 403 + if post.stickied.startswith("t:"): return {"error": "Can't unpin award pins!"}, 403 else: post.stickied = None else: pins = g.db.query(Submission.id).filter(Submission.stickied != None, Submission.is_banned == False).count() if pins > 2: if v.admin_level > 2: t = int(time.time()) + 3600 - post.stickied = f"t:{t}" + post.stickied = f"j:{t}" else: return {"error": "Can't exceed 3 pinned posts limit!"}, 403 else: post.stickied = v.username g.db.add(post) diff --git a/files/routes/front.py b/files/routes/front.py index 47841003f..54757a244 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -276,10 +276,20 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' blocked = [x[0] for x in g.db.query(UserBlock.user_id).filter_by(target_id=v.id).all()] pins = pins.filter(Submission.author_id.notin_(blocking), Submission.author_id.notin_(blocked)) - posts = pins.all() + posts + pins = pins.all() + + for pin in pins: + if (pin.stickied.startswith("t:") or pin.stickied.startswith("j:")) and int(time.time()) > int(pin.stickied[2:]): + pin.stickied = None + g.db.add(pin) + pins.remove(pin) + + posts = pins + posts if ids_only: posts = [x.id for x in posts] + g.db.commit() + return posts, next_exists diff --git a/files/routes/posts.py b/files/routes/posts.py index 36176934e..a029bcf37 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -217,6 +217,12 @@ def post_id(pid, anything=None, v=None): if len(comments) == len(comments2): offset = None comments = comments2 + for pin in pinned: + if pin.is_pinned.startswith("t:") and int(time.time()) > int(pin.is_pinned[2:]): + pin.is_pinned = None + g.db.add(pin) + pinned.remove(pin) + post.replies = pinned + comments post.views += 1 diff --git a/files/routes/votes.py b/files/routes/votes.py index 34093b4b5..52680c90b 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -5,7 +5,6 @@ from files.classes import * from flask import * from files.__main__ import app, limiter, cache from sqlalchemy.orm import joinedload -from .front import frontlist from os import environ defaultcolor = environ.get("DEFAULT_COLOR").strip() @@ -114,11 +113,6 @@ def api_vote_post(post_id, new, v): real = real ) g.db.add(vote) - - if post.stickied and post.stickied.startswith("t:") and int(time.time()) > int(post.stickied[2:]): - post.stickied = None - g.db.add(post) - cache.delete_memoized(frontlist) try: g.db.flush() @@ -187,10 +181,6 @@ def api_vote_comment(comment_id, new, v): g.db.add(vote) - if comment.is_pinned and comment.is_pinned.startswith("t:") and int(time.time()) > int(comment.is_pinned[2:]): - comment.is_pinned = None - g.db.add(comment) - try: g.db.flush() comment.upvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1).count() diff --git a/files/templates/submission.html b/files/templates/submission.html index 147dc5152..9cf0341ab 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -323,7 +323,7 @@ {% endif %} {% if v and v.admin_level > 1 and p.author.shadowbanned %}{% endif %} - {% if p.stickied and p.stickied.startswith('t:') %} + {% if p.stickied and (p.stickied.startswith('t:') or p.stickied.startswith('j:')) %} {% elif p.stickied %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 3c312bf54..6a1c7941a 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -166,7 +166,7 @@ {% endif %} {% if v and v.admin_level > 1 and p.author.shadowbanned %}{% endif %} - {% if p.stickied and p.stickied.startswith('t:') %} + {% if p.stickied and (p.stickied.startswith('t:') or p.stickied.startswith('j:')) %} {% elif p.stickied %} diff --git a/seed-db.sql b/seed-db.sql index 2e5ee11a2..5ca86d0ba 100644 --- a/seed-db.sql +++ b/seed-db.sql @@ -34,5 +34,4 @@ INSERT INTO public.users ( '', 'dark', '30409f', false, false, '', '', 0, false, 0, 0, 0, '', true, 0); - -SELECT pg_catalog.setval('public.users_id_seq', 6, true); \ No newline at end of file +SELECT pg_catalog.setval('public.users_id_seq', 7, true); \ No newline at end of file