From 1166119af0f1b1e2a45203b28679892da015e103 Mon Sep 17 00:00:00 2001 From: atrc445 Date: Thu, 16 Sep 2021 21:37:39 +0200 Subject: [PATCH 01/64] new awards query --- files/routes/awards.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/awards.py b/files/routes/awards.py index 60d560705..cff39b868 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -191,7 +191,7 @@ def get_awards(v): user_awards = v.awards for val in return_value: - val['owned'] = len([x for x in user_awards if x.kind == val['kind'] and not x.given]) + val['owned'] = user_awards.filter_by(kind=val['kind'], submission_id=None, comment_id=None).count() return jsonify(return_value) From 096a95b7a5aaee6fdd1bd4be41fed0c45cc85e3a Mon Sep 17 00:00:00 2001 From: atrc445 Date: Thu, 16 Sep 2021 22:18:03 +0200 Subject: [PATCH 02/64] fix dramacoin transfers why the fuck are there 3 duplicates of post_toast and who broke mine --- files/routes/users.py | 3 +-- files/templates/userpage.html | 15 +-------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/files/routes/users.py b/files/routes/users.py index 9ec611b2a..1bf46edf3 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -131,13 +131,12 @@ def transfer_coins(v, username): receiver.coins += amount g.db.add(receiver) g.db.add(v) + g.db.commit() transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['COINS_NAME']}!" send_notification(v.id, receiver, transfer_message) return {"message": f"{amount} {app.config['COINS_NAME']} transferred!"}, 200 - g.db.commit() - return {"message": f"{app.config['COINS_NAME']} transferred!"} diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 01d37ea87..b1d060c63 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -62,20 +62,7 @@ t.disabled = true; post_toast("/@{{u.username}}/transfer_coins", - xhr => { - if(xhr.status == 200) { - fetch("/@{{u.username}}/coins") - .then(r => r.json()) - .then(m => { - document.getElementById("profile-coins-amount").innerText = m["coins"]; - document.getElementById("profile-coins-amount-mobile").innerText = m["coins"]; - }) - - fetch("/@{{v.username}}/coins") - .then(r => r.json()) - .then(m => document.getElementById(`user-coins-amount`).innerText = m["coins"]) - } - }, + false, {"amount": document.getElementById(mobile ? "coins-transfer-amount-mobile" : "coins-transfer-amount").value} ); From 14e771dea3b2bbdb4e4e07545f787dca403853f6 Mon Sep 17 00:00:00 2001 From: atrc445 Date: Thu, 16 Sep 2021 22:29:40 +0200 Subject: [PATCH 03/64] fix (some) notifications --- files/helpers/alerts.py | 1 + 1 file changed, 1 insertion(+) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 3ef068440..3cc117915 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -41,6 +41,7 @@ def send_notification(vid, user, text, db=None): notif = Notification(comment_id=new_comment.id, user_id=uid) db.add(notif) + db.commit() def send_follow_notif(vid, user, text): From b82512f441fb5ac148b9d97a11fae601d433d9fc Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 16 Sep 2021 21:06:30 +0000 Subject: [PATCH 04/64] lol im aevann now --- files/routes/giphy.py | 4 ++-- files/routes/users.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/files/routes/giphy.py b/files/routes/giphy.py index e81ae0d32..91df32246 100644 --- a/files/routes/giphy.py +++ b/files/routes/giphy.py @@ -9,7 +9,7 @@ GIPHY_KEY = environ.get('GIPHY_KEY').rstrip() @app.route("/giphy", methods=["GET"]) @app.route("/giphy", methods=["GET"]) -def giphy(): +def giphy(path=None): searchTerm = request.args.get("searchTerm", "") limit = int(request.args.get("limit", 48)) @@ -19,4 +19,4 @@ def giphy(): url = f"https://api.giphy.com/v1/gifs/search?q={searchTerm}&api_key={GIPHY_KEY}&limit=48" else: url = f"https://api.giphy.com/v1/gifs?api_key={GIPHY_KEY}&limit=48" - return jsonify(requests.get(url).json()) \ No newline at end of file + return jsonify(requests.get(url).json()) diff --git a/files/routes/users.py b/files/routes/users.py index 1bf46edf3..e6953040c 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -134,7 +134,7 @@ def transfer_coins(v, username): g.db.commit() transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['COINS_NAME']}!" - send_notification(v.id, receiver, transfer_message) + send_notification(NOTIFICATIONS_ACCOUNT, receiver, transfer_message) return {"message": f"{amount} {app.config['COINS_NAME']} transferred!"}, 200 return {"message": f"{app.config['COINS_NAME']} transferred!"} From 0daeb07658ae691be9df199d8f33221b6214df12 Mon Sep 17 00:00:00 2001 From: Aevann1 <59999695+Aevann1@users.noreply.github.com> Date: Fri, 17 Sep 2021 07:59:45 +0200 Subject: [PATCH 05/64] Update users.py --- files/routes/users.py | 1 - 1 file changed, 1 deletion(-) diff --git a/files/routes/users.py b/files/routes/users.py index e6953040c..cdd514405 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -135,7 +135,6 @@ def transfer_coins(v, username): transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['COINS_NAME']}!" send_notification(NOTIFICATIONS_ACCOUNT, receiver, transfer_message) - return {"message": f"{amount} {app.config['COINS_NAME']} transferred!"}, 200 return {"message": f"{app.config['COINS_NAME']} transferred!"} From 835cde6d3d5730f5cd5743d12e88390b127a23b3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:00:58 +0200 Subject: [PATCH 06/64] fd --- files/routes/front.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/files/routes/front.py b/files/routes/front.py index 91fbc264f..be89770d8 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -32,6 +32,8 @@ def notifications(v): notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all() comments = [] + + t = time.time() notifs = [] for index, x in enumerate(notifications): @@ -44,6 +46,7 @@ def notifications(v): g.db.bulk_update_mappings(Notification, notifs) g.db.commit() + print(time.time() - t) next_exists = (len(comments) > 25) listing = comments[:25] From db25923f172d8a5dbc23feb40cfb1ba17a76a15c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:02:13 +0200 Subject: [PATCH 07/64] df --- files/routes/front.py | 101 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/files/routes/front.py b/files/routes/front.py index be89770d8..25602dd90 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -114,6 +114,107 @@ def notifications(v): is_notification_page=True) +@app.get("/notifications2") +@auth_required +def notifications2(v): + try: page = int(request.args.get('page', 1)) + except: page = 1 + messages = request.args.get('messages', False) + modmail = request.args.get('modmail', False) + posts = request.args.get('posts', False) + if modmail and v.admin_level == 6: + comments = g.db.query(Comment).filter(Comment.sentto==0).order_by(Comment.created_utc.desc()).offset(25*(page-1)).limit(26).all() + next_exists = (len(comments) > 25) + comments = comments[:25] + elif messages: + comments = g.db.query(Comment).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None).order_by(Comment.created_utc.desc(), not_(Comment.child_comments.any())).offset(25*(page-1)).limit(26).all() + next_exists = (len(comments) > 25) + comments = comments[:25] + elif posts: + notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all() + + comments = [] + + t = time.time() + + for index, x in enumerate(notifications): + c = x.comment + if x.read and index > 26: break + elif not x.read: + c.unread = True + x.read = True + g.db.add(x) + comments.append(c) + + g.db.commit() + print(time.time() - t) + + next_exists = (len(comments) > 25) + listing = comments[:25] + else: + + notifications = v.notifications.join(Notification.comment).filter( + Comment.is_banned == False, + Comment.deleted_utc == 0, + Comment.author_id != AUTOJANNY_ACCOUNT, + ).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all() + + next_exists = (len(notifications) > 25) + notifications = notifications[:25] + cids = [x.comment_id for x in notifications] + comments = get_comments(cids, v=v, load_parent=True) + + notifs = [] + i = 0 + for x in notifications: + try: + if not x.read: comments[i].unread = True + except: continue + notifs.append({'id': x.id, 'read': True}) + i += 1 + + g.db.bulk_update_mappings(Notification, notifs) + g.db.commit() + + if not posts: + listing = [] + for c in comments: + c._is_blocked = False + c._is_blocking = False + if c.parent_submission and c.parent_comment and c.parent_comment.author_id == v.id: + c.replies = [] + while c.parent_comment and c.parent_comment.author_id == v.id: + parent = c.parent_comment + if c not in parent.replies2: + parent.replies2 = parent.replies2 + [c] + parent.replies = parent.replies2 + c = parent + if c not in listing: + listing.append(c) + c.replies = c.replies2 + elif c.parent_submission: + c.replies = [] + if c not in listing: + listing.append(c) + else: + if c.parent_comment: + while c.level > 1: + c = c.parent_comment + + if c not in listing: + listing.append(c) + + + return render_template("notifications.html", + v=v, + notifications=listing, + next_exists=next_exists, + page=page, + standalone=True, + render_replies=True, + is_notification_page=True) + + @cache.memoize(timeout=86400) def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', **kwargs): From c4cc3ba0f8523de99c9130127b29b4ba972fce56 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:07:41 +0200 Subject: [PATCH 08/64] fd --- files/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index 73aec4224..7f2c77806 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -84,7 +84,8 @@ _engine=create_engine( app.config['DATABASE_URL'], poolclass=QueuePool, pool_size=int(environ.get("PG_POOL_SIZE",10)), - pool_use_lifo=True + pool_use_lifo=True, + echo=True ) def retry(f): From f1163eeac1234819592a10b3cb1db29767d256fa Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:11:05 +0200 Subject: [PATCH 09/64] fd --- files/routes/front.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/files/routes/front.py b/files/routes/front.py index 25602dd90..ec6ebbe0d 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -12,6 +12,23 @@ def slash_post(): # this is a test +@app.get("/testing") +def testing(v): + notifications = g.db.query(Notification).all() + + comments = [] + + t = time.time() + + for x in notifications: + x.read = True + g.db.add(x) + + g.db.commit() + print(time.time() - t) + return "sex" + + @app.get("/notifications") @auth_required def notifications(v): From db05c6b673aed630a13ee62d8f678e813b64a9f4 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:11:49 +0200 Subject: [PATCH 10/64] fd --- files/routes/front.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/front.py b/files/routes/front.py index ec6ebbe0d..b343731f7 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -13,7 +13,7 @@ def slash_post(): # this is a test @app.get("/testing") -def testing(v): +def testing(): notifications = g.db.query(Notification).all() comments = [] From 78e2d657214eb495cb73c7811a6c2987eb9be909 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:12:40 +0200 Subject: [PATCH 11/64] fd --- files/routes/front.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/files/routes/front.py b/files/routes/front.py index b343731f7..5b79677db 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -15,8 +15,6 @@ def slash_post(): @app.get("/testing") def testing(): notifications = g.db.query(Notification).all() - - comments = [] t = time.time() From ee1ccf0ba9903746244a44ffc658909dc0a7c2bf Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:13:45 +0200 Subject: [PATCH 12/64] fd --- files/routes/front.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/front.py b/files/routes/front.py index 5b79677db..6731b4afa 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -14,7 +14,7 @@ def slash_post(): @app.get("/testing") def testing(): - notifications = g.db.query(Notification).all() + notifications = g.db.query(Notification) t = time.time() From f936b4a11412b3519b9f9840ac67bd7e87439528 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:14:10 +0200 Subject: [PATCH 13/64] fd --- files/routes/front.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/front.py b/files/routes/front.py index 6731b4afa..8def5d9b5 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -14,7 +14,7 @@ def slash_post(): @app.get("/testing") def testing(): - notifications = g.db.query(Notification) + notifications = g.db.query(Notification).limit(25) t = time.time() From 0dc5045052c6734700626b26c73061ac232a19f7 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:18:59 +0200 Subject: [PATCH 14/64] fd --- files/routes/front.py | 130 ++---------------------------------------- 1 file changed, 4 insertions(+), 126 deletions(-) diff --git a/files/routes/front.py b/files/routes/front.py index 8def5d9b5..38711964b 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -10,23 +10,6 @@ defaulttimefilter = environ.get("DEFAULT_TIME_FILTER", "all").strip() def slash_post(): return redirect("/") -# this is a test - -@app.get("/testing") -def testing(): - notifications = g.db.query(Notification).limit(25) - - t = time.time() - - for x in notifications: - x.read = True - g.db.add(x) - - g.db.commit() - print(time.time() - t) - return "sex" - - @app.get("/notifications") @auth_required def notifications(v): @@ -48,110 +31,6 @@ def notifications(v): comments = [] - t = time.time() - notifs = [] - - for index, x in enumerate(notifications): - c = x.comment - if x.read and index > 26: break - elif not x.read: - c.unread = True - notifs.append({'id': x.id, 'read': True}) - comments.append(c) - - g.db.bulk_update_mappings(Notification, notifs) - g.db.commit() - print(time.time() - t) - - next_exists = (len(comments) > 25) - listing = comments[:25] - else: - - notifications = v.notifications.join(Notification.comment).filter( - Comment.is_banned == False, - Comment.deleted_utc == 0, - Comment.author_id != AUTOJANNY_ACCOUNT, - ).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all() - - next_exists = (len(notifications) > 25) - notifications = notifications[:25] - cids = [x.comment_id for x in notifications] - comments = get_comments(cids, v=v, load_parent=True) - - notifs = [] - i = 0 - for x in notifications: - try: - if not x.read: comments[i].unread = True - except: continue - notifs.append({'id': x.id, 'read': True}) - i += 1 - - g.db.bulk_update_mappings(Notification, notifs) - g.db.commit() - - if not posts: - listing = [] - for c in comments: - c._is_blocked = False - c._is_blocking = False - if c.parent_submission and c.parent_comment and c.parent_comment.author_id == v.id: - c.replies = [] - while c.parent_comment and c.parent_comment.author_id == v.id: - parent = c.parent_comment - if c not in parent.replies2: - parent.replies2 = parent.replies2 + [c] - parent.replies = parent.replies2 - c = parent - if c not in listing: - listing.append(c) - c.replies = c.replies2 - elif c.parent_submission: - c.replies = [] - if c not in listing: - listing.append(c) - else: - if c.parent_comment: - while c.level > 1: - c = c.parent_comment - - if c not in listing: - listing.append(c) - - - return render_template("notifications.html", - v=v, - notifications=listing, - next_exists=next_exists, - page=page, - standalone=True, - render_replies=True, - is_notification_page=True) - - -@app.get("/notifications2") -@auth_required -def notifications2(v): - try: page = int(request.args.get('page', 1)) - except: page = 1 - messages = request.args.get('messages', False) - modmail = request.args.get('modmail', False) - posts = request.args.get('posts', False) - if modmail and v.admin_level == 6: - comments = g.db.query(Comment).filter(Comment.sentto==0).order_by(Comment.created_utc.desc()).offset(25*(page-1)).limit(26).all() - next_exists = (len(comments) > 25) - comments = comments[:25] - elif messages: - comments = g.db.query(Comment).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None).order_by(Comment.created_utc.desc(), not_(Comment.child_comments.any())).offset(25*(page-1)).limit(26).all() - next_exists = (len(comments) > 25) - comments = comments[:25] - elif posts: - notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all() - - comments = [] - - t = time.time() - for index, x in enumerate(notifications): c = x.comment if x.read and index > 26: break @@ -162,7 +41,6 @@ def notifications2(v): comments.append(c) g.db.commit() - print(time.time() - t) next_exists = (len(comments) > 25) listing = comments[:25] @@ -179,16 +57,16 @@ def notifications2(v): cids = [x.comment_id for x in notifications] comments = get_comments(cids, v=v, load_parent=True) - notifs = [] i = 0 for x in notifications: try: - if not x.read: comments[i].unread = True + if not x.read: + comments[i].unread = True + x.read = True + g.db.add(x) except: continue - notifs.append({'id': x.id, 'read': True}) i += 1 - g.db.bulk_update_mappings(Notification, notifs) g.db.commit() if not posts: From 7b6f5d9def67b0379b226349c4e029e9f0430a43 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:19:43 +0200 Subject: [PATCH 15/64] fd --- files/routes/front.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/routes/front.py b/files/routes/front.py index 38711964b..8bc49d50b 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -27,7 +27,7 @@ def notifications(v): next_exists = (len(comments) > 25) comments = comments[:25] elif posts: - notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all() + notifications = v.notifications.options(lazyload('*')).join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all() comments = [] @@ -46,7 +46,7 @@ def notifications(v): listing = comments[:25] else: - notifications = v.notifications.join(Notification.comment).filter( + notifications = v.notifications.options(lazyload('*')).join(Notification.comment).filter( Comment.is_banned == False, Comment.deleted_utc == 0, Comment.author_id != AUTOJANNY_ACCOUNT, From 62a5278af4bb6fbe77931744f80d39652555c200 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:21:32 +0200 Subject: [PATCH 16/64] fd --- files/routes/front.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/files/routes/front.py b/files/routes/front.py index 8bc49d50b..b52047316 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -10,6 +10,12 @@ defaulttimefilter = environ.get("DEFAULT_TIME_FILTER", "all").strip() def slash_post(): return redirect("/") +@app.get("/testing") +def testing(): + notifications = g.db.query(Notification).options(lazyload('*')).join(Notification.comment).limit(26) + notifications2 = g.db.query(Notification).join(Notification.comment).limit(26) + return "sex" + @app.get("/notifications") @auth_required def notifications(v): From f7ecf95d64d009eec01a9fef26ac1272106efcf9 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:24:44 +0200 Subject: [PATCH 17/64] fd --- files/routes/front.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/files/routes/front.py b/files/routes/front.py index b52047316..ee87ea5b8 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -12,8 +12,9 @@ def slash_post(): @app.get("/testing") def testing(): - notifications = g.db.query(Notification).options(lazyload('*')).join(Notification.comment).limit(26) - notifications2 = g.db.query(Notification).join(Notification.comment).limit(26) + notifications = g.db.query(Notification).options(lazyload('*')) + print("FUCK\nFUCK\nFUCK") + notifications2 = g.db.query(Notification) return "sex" @app.get("/notifications") From 5bcf63250928c69d78facda86c9d5ca305a285c8 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:25:11 +0200 Subject: [PATCH 18/64] fd --- files/routes/front.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/routes/front.py b/files/routes/front.py index ee87ea5b8..979fb0de5 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -12,9 +12,9 @@ def slash_post(): @app.get("/testing") def testing(): - notifications = g.db.query(Notification).options(lazyload('*')) + notifications = g.db.query(Notification).options(lazyload('*')).all() print("FUCK\nFUCK\nFUCK") - notifications2 = g.db.query(Notification) + notifications2 = g.db.query(Notification).all() return "sex" @app.get("/notifications") From 6cc19ce02ab36a5b4819c06adf60cf344b78dbcb Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:29:05 +0200 Subject: [PATCH 19/64] sfd --- files/classes/clients.py | 4 +-- files/classes/user.py | 30 ++++++++-------- files/helpers/alerts.py | 2 +- files/helpers/filters.py | 2 +- files/helpers/get.py | 30 ++++++++-------- files/helpers/wrappers.py | 8 ++--- files/mail/mail.py | 2 +- files/routes/admin.py | 72 +++++++++++++++++++-------------------- files/routes/awards.py | 12 +++---- files/routes/comments.py | 22 ++++++------ files/routes/discord.py | 2 +- files/routes/front.py | 18 +++++----- files/routes/login.py | 30 ++++++++-------- files/routes/oauth.py | 22 ++++++------ files/routes/posts.py | 32 ++++++++--------- files/routes/reporting.py | 8 ++--- files/routes/search.py | 4 +-- files/routes/settings.py | 12 +++---- files/routes/static.py | 32 ++++++++--------- files/routes/users.py | 32 ++++++++--------- files/routes/votes.py | 12 +++---- 21 files changed, 194 insertions(+), 194 deletions(-) diff --git a/files/classes/clients.py b/files/classes/clients.py index b1449e11b..0721e240e 100644 --- a/files/classes/clients.py +++ b/files/classes/clients.py @@ -27,7 +27,7 @@ class OauthApp(Base, Stndrd): def idlist(self, page=1, **kwargs): - posts = g.db.query(Submission.id).options(lazyload('*')).filter_by(app_id=self.id) + posts = g.db.query(Submission.id).options(lazyload('*')).options(lazyload('*')).filter_by(app_id=self.id) posts=posts.order_by(Submission.created_utc.desc()) @@ -37,7 +37,7 @@ class OauthApp(Base, Stndrd): def comments_idlist(self, page=1, **kwargs): - posts = g.db.query(Comment.id).options(lazyload('*')).filter_by(app_id=self.id) + posts = g.db.query(Comment.id).options(lazyload('*')).options(lazyload('*')).filter_by(app_id=self.id) posts=posts.order_by(Comment.created_utc.desc()) diff --git a/files/classes/user.py b/files/classes/user.py index 453eef371..254d49ea3 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -155,7 +155,7 @@ class User(Base, Stndrd, Age_times): def has_block(self, target): - return g.db.query(UserBlock).filter_by( + return g.db.query(UserBlock).options(lazyload('*')).filter_by( user_id=self.id, target_id=target.id).first() @property @@ -164,7 +164,7 @@ class User(Base, Stndrd, Age_times): def any_block_exists(self, other): - return g.db.query(UserBlock).filter( + return g.db.query(UserBlock).options(lazyload('*')).filter( or_(and_(UserBlock.user_id == self.id, UserBlock.target_id == other.id), and_( UserBlock.user_id == other.id, UserBlock.target_id == self.id))).first() @@ -187,7 +187,7 @@ class User(Base, Stndrd, Age_times): if self.shadowbanned and not (v and (v.admin_level >= 3 or v.id == self.id)): return [] - submissions = g.db.query(Submission).options(lazyload('*')).filter_by(author_id=self.id, is_pinned=False) + submissions = g.db.query(Submission).options(lazyload('*')).options(lazyload('*')).filter_by(author_id=self.id, is_pinned=False) if not (v and (v.admin_level >= 3 or v.id == self.id)): submissions = submissions.filter_by(deleted_utc=0, is_banned=False, private=False) @@ -233,7 +233,7 @@ class User(Base, Stndrd, Age_times): def banned_by(self): if not self.is_suspended: return None - return g.db.query(User).filter_by(id=self.is_banned).first() + return g.db.query(User).options(lazyload('*')).filter_by(id=self.is_banned).first() def has_badge(self, badgedef_id): return self.badges.filter_by(badge_id=badgedef_id).first() @@ -310,11 +310,11 @@ class User(Base, Stndrd, Age_times): awards = {} - posts_idlist = g.db.query(Submission.id).filter_by(author_id=self.id).subquery() - comments_idlist = g.db.query(Comment.id).filter_by(author_id=self.id).subquery() + posts_idlist = g.db.query(Submission.id).options(lazyload('*')).filter_by(author_id=self.id).subquery() + comments_idlist = g.db.query(Comment.id).options(lazyload('*')).filter_by(author_id=self.id).subquery() - post_awards = g.db.query(AwardRelationship).filter(AwardRelationship.submission_id.in_(posts_idlist)).all() - comment_awards = g.db.query(AwardRelationship).filter(AwardRelationship.comment_id.in_(comments_idlist)).all() + post_awards = g.db.query(AwardRelationship).options(lazyload('*')).filter(AwardRelationship.submission_id.in_(posts_idlist)).all() + comment_awards = g.db.query(AwardRelationship).options(lazyload('*')).filter(AwardRelationship.comment_id.in_(comments_idlist)).all() total_awards = post_awards + comment_awards @@ -345,7 +345,7 @@ class User(Base, Stndrd, Age_times): @lazy def alts(self): - subq = g.db.query(Alt).filter( + subq = g.db.query(Alt).options(lazyload('*')).filter( or_( Alt.user1 == self.id, Alt.user2 == self.id @@ -407,7 +407,7 @@ class User(Base, Stndrd, Age_times): def has_follower(self, user): - return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).first() + return g.db.query(Follow).options(lazyload('*')).filter_by(target_id=self.id, user_id=user.id).first() @property def banner_url(self): @@ -511,16 +511,16 @@ class User(Base, Stndrd, Age_times): OauthApp.id.asc()).all()] def subscribed_idlist(self, page=1): - posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all() + posts = g.db.query(Subscription.submission_id).options(lazyload('*')).filter_by(user_id=self.id).all() return [x[0] for x in posts] def saved_idlist(self, page=1): - posts = g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=False, + posts = g.db.query(Submission.id).options(lazyload('*')).options(lazyload('*')).filter_by(is_banned=False, deleted_utc=0 ) - saved = g.db.query(SaveRelationship.submission_id).filter(SaveRelationship.user_id == self.id).subquery() + saved = g.db.query(SaveRelationship.submission_id).options(lazyload('*')).filter(SaveRelationship.user_id == self.id).subquery() posts = posts.filter(Submission.id.in_(saved)) if self.admin_level == 0: @@ -542,9 +542,9 @@ class User(Base, Stndrd, Age_times): def saved_comment_idlist(self, page=1): - comments = g.db.query(Comment.id).options(lazyload('*')).filter_by(is_banned=False, deleted_utc=0) + comments = g.db.query(Comment.id).options(lazyload('*')).options(lazyload('*')).filter_by(is_banned=False, deleted_utc=0) - saved = g.db.query(SaveRelationship.submission_id).filter(SaveRelationship.user_id == self.id).subquery() + saved = g.db.query(SaveRelationship.submission_id).options(lazyload('*')).filter(SaveRelationship.user_id == self.id).subquery() comments = comments.filter(Comment.id.in_(saved)) if self.admin_level == 0: diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 3cc117915..bc81e63ca 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -187,7 +187,7 @@ def send_admin(vid, text): new_aux = CommentAux(id=new_comment.id, body=text, body_html=text_html) g.db.add(new_aux) - admins = g.db.query(User).filter(User.admin_level > 0).all() + admins = g.db.query(User).options(lazyload('*')).filter(User.admin_level > 0).all() for admin in admins: notif = Notification(comment_id=new_comment.id, user_id=admin.id) g.db.add(notif) diff --git a/files/helpers/filters.py b/files/helpers/filters.py index c4c33cebe..e4c1698f2 100644 --- a/files/helpers/filters.py +++ b/files/helpers/filters.py @@ -30,7 +30,7 @@ def filter_comment_html(html_text): # search db for domain rules that prohibit commenting bans = [ - x for x in g.db.query(BannedDomain).filter(BannedDomain.domain.in_(list(domain_list))).all()] + x for x in g.db.query(BannedDomain).options(lazyload('*')).filter(BannedDomain.domain.in_(list(domain_list))).all()] if bans: return bans diff --git a/files/helpers/get.py b/files/helpers/get.py index 864832ee7..c0ecd46c8 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -24,7 +24,7 @@ def get_user(username, v=None, graceful=False): return None if v: - block = g.db.query(UserBlock).filter( + block = g.db.query(UserBlock).options(lazyload('*')).filter( or_( and_( UserBlock.user_id == v.id, @@ -43,16 +43,16 @@ def get_user(username, v=None, graceful=False): def get_account(id, v=None): - user = g.db.query(User).filter_by(id = id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id = id).first() if not user: try: id = int(str(id), 36) except: abort(404) - user = g.db.query(User).filter_by(id = id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id = id).first() if not user: abort(404) if v: - block = g.db.query(UserBlock).filter( + block = g.db.query(UserBlock).options(lazyload('*')).filter( or_( and_( UserBlock.user_id == v.id, @@ -73,7 +73,7 @@ def get_account(id, v=None): def get_post(i, v=None, graceful=False, **kwargs): if v: - vt = g.db.query(Vote).filter_by( + vt = g.db.query(Vote).options(lazyload('*')).filter_by( user_id=v.id, submission_id=i).subquery() blocking = v.blocking.subquery() @@ -122,7 +122,7 @@ def get_posts(pids, v=None): pids=tuple(pids) if v: - vt = g.db.query(Vote).filter( + vt = g.db.query(Vote).options(lazyload('*')).filter( Vote.submission_id.in_(pids), Vote.user_id==v.id ).subquery() @@ -155,7 +155,7 @@ def get_posts(pids, v=None): output[i]._is_blocking = query[i][2] or 0 output[i]._is_blocked = query[i][3] or 0 else: - output = g.db.query(Submission,).filter(Submission.id.in_(pids)).all() + output = g.db.query(Submission,).options(lazyload('*')).filter(Submission.id.in_(pids)).all() return sorted(output, key=lambda x: pids.index(x.id)) @@ -163,11 +163,11 @@ def get_comment(i, v=None, graceful=False, **kwargs): if v: - comment=g.db.query(Comment).filter(Comment.id == i).first() + comment=g.db.query(Comment).options(lazyload('*')).filter(Comment.id == i).first() if not comment and not graceful: abort(404) - block = g.db.query(UserBlock).filter( + block = g.db.query(UserBlock).options(lazyload('*')).filter( or_( and_( UserBlock.user_id == v.id, @@ -179,14 +179,14 @@ def get_comment(i, v=None, graceful=False, **kwargs): ) ).first() - vts = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id) - vt = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).first() + vts = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id) + vt = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first() comment._is_blocking = block and block.user_id == v.id comment._is_blocked = block and block.target_id == v.id comment.voted = vt.vote_type if vt else 0 else: - comment = g.db.query(Comment).filter(Comment.id == i).first() + comment = g.db.query(Comment).options(lazyload('*')).filter(Comment.id == i).first() if not comment and not graceful:abort(404) return comment @@ -199,7 +199,7 @@ def get_comments(cids, v=None, load_parent=False): cids=tuple(cids) if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + votes = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id).subquery() blocking = v.blocking.subquery() @@ -238,7 +238,7 @@ def get_comments(cids, v=None, load_parent=False): output.append(comment) else: - output = g.db.query(Comment).join(Comment.author).filter(Comment.id.in_(cids), User.shadowbanned == False).all() + output = g.db.query(Comment).join(Comment.author).options(lazyload('*')).filter(Comment.id.in_(cids), User.shadowbanned == False).all() if load_parent: parents = [x.parent_comment_id for x in output if x.parent_comment_id] @@ -263,7 +263,7 @@ def get_domain(s): domain_list = tuple(list(domain_list)) - doms = [x for x in g.db.query(BannedDomain).filter( + doms = [x for x in g.db.query(BannedDomain).options(lazyload('*')).filter( BannedDomain.domain.in_(domain_list)).all()] if not doms: diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index cdc0d670a..507adee0c 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -13,7 +13,7 @@ def get_logged_in_user(): token = request.headers.get("Authorization") if not token: return None - client = g.db.query(ClientAuth).filter(ClientAuth.access_token == token).first() + client = g.db.query(ClientAuth).options(lazyload('*')).filter(ClientAuth.access_token == token).first() x = (client.user, client) if client else (None, None) @@ -24,7 +24,7 @@ def get_logged_in_user(): nonce = session.get("login_nonce", 0) if not uid: x= (None, None) try: - if g.db: v = g.db.query(User).filter_by(id=uid).first() + if g.db: v = g.db.query(User).options(lazyload('*')).filter_by(id=uid).first() else: v = None except: v = None @@ -54,7 +54,7 @@ def check_ban_evade(v): v.ban(reason="ban evasion") send_notification(NOTIFICATIONS_ACCOUNT, v, "Your account has been permanently suspended for the following reason:\n\n> ban evasion") - for post in g.db.query(Submission).filter_by(author_id=v.id).all(): + for post in g.db.query(Submission).options(lazyload('*')).filter_by(author_id=v.id).all(): if post.is_banned: continue @@ -74,7 +74,7 @@ def check_ban_evade(v): g.db.flush() - for comment in g.db.query(Comment).filter_by(author_id=v.id).all(): + for comment in g.db.query(Comment).options(lazyload('*')).filter_by(author_id=v.id).all(): if comment.is_banned: continue diff --git a/files/mail/mail.py b/files/mail/mail.py index de7093225..f0ca51c20 100644 --- a/files/mail/mail.py +++ b/files/mail/mail.py @@ -79,7 +79,7 @@ def activate(v): if not validate_hash(f"{email}+{id}+{timestamp}", token): abort(403) - user = g.db.query(User).filter_by(id=id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=id).first() if not user: abort(404) diff --git a/files/routes/admin.py b/files/routes/admin.py index dacb39858..12baabaec 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -31,14 +31,14 @@ def revert_actions(v, username): user = get_user(username) if not user: abort(404) - items = g.db.query(Submission).options(lazyload('*')).filter_by(removed_by=user.id).all() + g.db.query(Comment).options(lazyload('*')).filter_by(removed_by=user.id).all() + items = g.db.query(Submission).options(lazyload('*')).options(lazyload('*')).filter_by(removed_by=user.id).all() + g.db.query(Comment).options(lazyload('*')).options(lazyload('*')).filter_by(removed_by=user.id).all() for item in items: item.is_banned = False item.removed_by = None g.db.add(item) - users = g.db.query(User).options(lazyload('*')).filter_by(is_banned=user.id).all() + users = g.db.query(User).options(lazyload('*')).options(lazyload('*')).filter_by(is_banned=user.id).all() for user in users: user.unban() @@ -144,7 +144,7 @@ def monthly(v): if 'pcm' in request.host or ('rdrama' in request.host and v.id in [1,12,28,29,747,995,1480]) or ('rdrama' not in request.host and 'pcm' not in request.host): thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id _awards = [] - for u in g.db.query(User).filter(User.patron > 0).all(): + for u in g.db.query(User).options(lazyload('*')).filter(User.patron > 0).all(): grant_awards = {} if u.patron == 1: @@ -224,7 +224,7 @@ def post_rules(v): @auth_required def shadowbanned(v): if not (v and v.admin_level == 6): abort(404) - users = [x for x in g.db.query(User).filter_by(shadowbanned = True).all()] + users = [x for x in g.db.query(User).options(lazyload('*')).filter_by(shadowbanned = True).all()] return render_template("banned.html", v=v, users=users) @@ -232,7 +232,7 @@ def shadowbanned(v): @auth_required def agendaposters(v): if not (v and v.admin_level == 6): abort(404) - users = [x for x in g.db.query(User).filter_by(agendaposter = True).all()] + users = [x for x in g.db.query(User).options(lazyload('*')).filter_by(agendaposter = True).all()] return render_template("banned.html", v=v, users=users) @@ -260,7 +260,7 @@ def reported_posts(v): page = max(1, int(request.args.get("page", 1))) - posts = g.db.query(Submission).filter_by( + posts = g.db.query(Submission).options(lazyload('*')).filter_by( is_approved=0, is_banned=False ).join(Submission.flags).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26) @@ -352,7 +352,7 @@ def badge_grant_post(v): except: abort(400) if user.has_badge(badge_id): - g.db.query(Badge).filter_by(badge_id=badge_id, user_id=user.id,).delete() + g.db.query(Badge).options(lazyload('*')).filter_by(badge_id=badge_id, user_id=user.id,).delete() return redirect("/admin/badge_grant") new_badge = Badge(badge_id=badge_id, @@ -376,7 +376,7 @@ def badge_grant_post(v): send_notification(NOTIFICATIONS_ACCOUNT, user, text) if badge_id == 16 and user.has_badge(17): - g.db.query(Badge).filter_by(badge_id=17, user_id=user.id).delete() + g.db.query(Badge).options(lazyload('*')).filter_by(badge_id=17, user_id=user.id).delete() elif badge_id in [21,22,23,24,28]: user.patron = int(str(badge_id)[-1]) @@ -446,7 +446,7 @@ def users_list(v): page = int(request.args.get("page", 1)) - users = g.db.query(User).filter_by(is_banned=0 + users = g.db.query(User).options(lazyload('*')).filter_by(is_banned=0 ).order_by(User.created_utc.desc() ).offset(25 * (page - 1)).limit(26) @@ -597,7 +597,7 @@ def admin_removed(v): page = int(request.args.get("page", 1)) - ids = g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=True).order_by( + ids = g.db.query(Submission.id).options(lazyload('*')).options(lazyload('*')).filter_by(is_banned=True).order_by( Submission.id.desc()).offset(25 * (page - 1)).limit(26).all() ids=[x[0] for x in ids] @@ -621,7 +621,7 @@ def admin_removed(v): def admin_image_purge(v): name = request.form.get("url") - image = g.db.query(Image).filter(Image.text == name).first() + image = g.db.query(Image).options(lazyload('*')).filter(Image.text == name).first() if image: requests.delete(f'https://api.imgur.com/3/image/{image.deletehash}', headers = {"Authorization": f"Client-ID {IMGUR_KEY}"}) headers = {"Authorization": f"Bearer {CF_KEY}", "Content-Type": "application/json"} @@ -663,7 +663,7 @@ def admin_image_ban(v): h = ''.join([str(d) for d in bindigits]) #check db for existing - badpic = g.db.query(BadPic).filter_by( + badpic = g.db.query(BadPic).options(lazyload('*')).filter_by( phash=h ).first() @@ -688,7 +688,7 @@ def admin_image_ban(v): @admin_level_required(6) @validate_formkey def agendaposter(user_id, v): - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() expiry = request.form.get("days", 0) if expiry: @@ -741,7 +741,7 @@ def agendaposter(user_id, v): @admin_level_required(6) @validate_formkey def shadowban(user_id, v): - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() if user.admin_level != 0: abort(403) user.shadowbanned = True g.db.add(user) @@ -766,7 +766,7 @@ def shadowban(user_id, v): @admin_level_required(6) @validate_formkey def unshadowban(user_id, v): - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() if user.admin_level != 0: abort(403) user.shadowbanned = False g.db.add(user) @@ -790,7 +790,7 @@ def unshadowban(user_id, v): @admin_level_required(6) @validate_formkey def verify(user_id, v): - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() user.verified = "Verified" g.db.add(user) g.db.commit() @@ -800,7 +800,7 @@ def verify(user_id, v): @admin_level_required(6) @validate_formkey def unverify(user_id, v): - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() user.verified = None g.db.add(user) g.db.commit() @@ -812,7 +812,7 @@ def unverify(user_id, v): @validate_formkey def admin_title_change(user_id, v): - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() if user.admin_level != 0: abort(403) @@ -821,7 +821,7 @@ def admin_title_change(user_id, v): user.customtitleplain=new_name new_name = sanitize(new_name) - user=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=user.id).first() + user=g.db.query(User).with_for_update().options(lazyload('*')).options(lazyload('*')).filter_by(id=user.id).first() user.customtitle=new_name user.flairchanged = bool(request.form.get("locked")) g.db.add(user) @@ -845,7 +845,7 @@ def admin_title_change(user_id, v): @validate_formkey def ban_user(user_id, v): - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() if user.admin_level >= v.admin_level: abort(403) @@ -913,7 +913,7 @@ def ban_user(user_id, v): @validate_formkey def unban_user(user_id, v): - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() if not user: abort(400) @@ -947,7 +947,7 @@ def unban_user(user_id, v): @validate_formkey def ban_post(post_id, v): - post = g.db.query(Submission).filter_by(id=post_id).first() + post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first() if not post: abort(400) @@ -988,7 +988,7 @@ def ban_post(post_id, v): @validate_formkey def unban_post(post_id, v): - post = g.db.query(Submission).filter_by(id=post_id).first() + post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first() if not post: abort(400) @@ -1018,7 +1018,7 @@ def unban_post(post_id, v): @validate_formkey def api_distinguish_post(post_id, v): - post = g.db.query(Submission).filter_by(id=post_id).first() + post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first() if not post: abort(404) @@ -1042,7 +1042,7 @@ def api_distinguish_post(post_id, v): @admin_level_required(3) def api_sticky_post(post_id, v): - post = g.db.query(Submission).filter_by(id=post_id).first() + post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first() if post: post.stickied = not (post.stickied) g.db.add(post) @@ -1064,7 +1064,7 @@ def api_sticky_post(post_id, v): @auth_required def api_pin_post(post_id, v): - post = g.db.query(Submission).filter_by(id=post_id).first() + post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first() if post: post.is_pinned = not (post.is_pinned) g.db.add(post) @@ -1077,7 +1077,7 @@ def api_pin_post(post_id, v): @admin_level_required(1) def api_ban_comment(c_id, v): - comment = g.db.query(Comment).filter_by(id=c_id).first() + comment = g.db.query(Comment).options(lazyload('*')).filter_by(id=c_id).first() if not comment: abort(404) @@ -1100,7 +1100,7 @@ def api_ban_comment(c_id, v): @admin_level_required(1) def api_unban_comment(c_id, v): - comment = g.db.query(Comment).filter_by(id=c_id).first() + comment = g.db.query(Comment).options(lazyload('*')).filter_by(id=c_id).first() if not comment: abort(404) g.db.add(comment) @@ -1172,7 +1172,7 @@ def admin_toggle_ban_domain(v): reason=request.form.get("reason", "").strip() - d = g.db.query(BannedDomain).filter_by(domain=domain).first() + d = g.db.query(BannedDomain).options(lazyload('*')).filter_by(domain=domain).first() if d: g.db.delete(d) else: d = BannedDomain(domain=domain, reason=reason) @@ -1190,14 +1190,14 @@ def admin_nuke_user(v): user=get_user(request.form.get("user")) - for post in g.db.query(Submission).filter_by(author_id=user.id).all(): + for post in g.db.query(Submission).options(lazyload('*')).filter_by(author_id=user.id).all(): if post.is_banned: continue post.is_banned=True g.db.add(post) - for comment in g.db.query(Comment).filter_by(author_id=user.id).all(): + for comment in g.db.query(Comment).options(lazyload('*')).filter_by(author_id=user.id).all(): if comment.is_banned: continue @@ -1222,14 +1222,14 @@ def admin_nunuke_user(v): user=get_user(request.form.get("user")) - for post in g.db.query(Submission).filter_by(author_id=user.id).all(): + for post in g.db.query(Submission).options(lazyload('*')).filter_by(author_id=user.id).all(): if not post.is_banned: continue post.is_banned=False g.db.add(post) - for comment in g.db.query(Comment).filter_by(author_id=user.id).all(): + for comment in g.db.query(Comment).options(lazyload('*')).filter_by(author_id=user.id).all(): if not comment.is_banned: continue @@ -1273,11 +1273,11 @@ def chart(v): daily_times = [time.strftime("%d", time.gmtime(day_cutoffs[i + 1])) for i in range(len(day_cutoffs) - 1)][2:][::-1] - daily_signups = [g.db.query(User).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][2:][::-1] + daily_signups = [g.db.query(User).options(lazyload('*')).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][2:][::-1] - post_stats = [g.db.query(Submission).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.is_banned == False).count() for i in range(len(day_cutoffs) - 1)][2:][::-1] + post_stats = [g.db.query(Submission).options(lazyload('*')).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.is_banned == False).count() for i in range(len(day_cutoffs) - 1)][2:][::-1] - comment_stats = [g.db.query(Comment).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id != 1).count() for i in range(len(day_cutoffs) - 1)][2:][::-1] + comment_stats = [g.db.query(Comment).options(lazyload('*')).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id != 1).count() for i in range(len(day_cutoffs) - 1)][2:][::-1] # create multiple charts signup_chart = plt.subplot2grid((20, 4), (0, 0), rowspan=5, colspan=4) diff --git a/files/routes/awards.py b/files/routes/awards.py index cff39b868..9a6034194 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -209,7 +209,7 @@ def award_post(pid, v): if kind not in AWARDS: return {"error": "That award doesn't exist."}, 404 - post_award = g.db.query(AwardRelationship).filter( + post_award = g.db.query(AwardRelationship).options(lazyload('*')).filter( and_( AwardRelationship.kind == kind, AwardRelationship.user_id == v.id, @@ -221,7 +221,7 @@ def award_post(pid, v): if not post_award: return {"error": "You don't have that award."}, 404 - post = g.db.query(Submission).filter_by(id=pid).first() + post = g.db.query(Submission).options(lazyload('*')).filter_by(id=pid).first() if not post or post.is_banned or post.deleted_utc > 0: return {"error": "That post doesn't exist or has been deleted or removed."}, 404 @@ -229,7 +229,7 @@ def award_post(pid, v): if post.author_id == v.id: return {"error": "You can't award yourself."}, 403 - existing_award = g.db.query(AwardRelationship).filter( + existing_award = g.db.query(AwardRelationship).options(lazyload('*')).filter( and_( AwardRelationship.submission_id == post.id, AwardRelationship.user_id == v.id, @@ -275,7 +275,7 @@ def award_comment(cid, v): if kind not in AWARDS: return {"error": "That award doesn't exist."}, 404 - comment_award = g.db.query(AwardRelationship).filter( + comment_award = g.db.query(AwardRelationship).options(lazyload('*')).filter( and_( AwardRelationship.kind == kind, AwardRelationship.user_id == v.id, @@ -287,7 +287,7 @@ def award_comment(cid, v): if not comment_award: return {"error": "You don't have that award."}, 404 - c = g.db.query(Comment).filter_by(id=cid).first() + c = g.db.query(Comment).options(lazyload('*')).filter_by(id=cid).first() if not c or c.is_banned or c.deleted_utc > 0: return {"error": "That comment doesn't exist or has been deleted or removed."}, 404 @@ -295,7 +295,7 @@ def award_comment(cid, v): if c.author_id == v.id: return {"error": "You can't award yourself."}, 403 - existing_award = g.db.query(AwardRelationship).filter( + existing_award = g.db.query(AwardRelationship).options(lazyload('*')).filter( and_( AwardRelationship.comment_id == c.id, AwardRelationship.user_id == v.id, diff --git a/files/routes/comments.py b/files/routes/comments.py index 7deb489b9..c5fd329a2 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -82,7 +82,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): post.replies=[top_comment] if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + votes = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id).subquery() blocking = v.blocking.subquery() @@ -184,7 +184,7 @@ def api_comment(v): return {"error": reason}, 401 # check existing - existing = g.db.query(Comment).join(CommentAux).filter(Comment.author_id == v.id, + existing = g.db.query(Comment).join(CommentAux).options(lazyload('*')).filter(Comment.author_id == v.id, Comment.deleted_utc == 0, Comment.parent_comment_id == parent_comment_id, Comment.parent_submission == parent_submission, @@ -260,7 +260,7 @@ def api_comment(v): fragment='') check_url = urlunparse(check_url) - badlink = g.db.query(BadLink).filter( + badlink = g.db.query(BadLink).options(lazyload('*')).filter( literal(check_url).contains( BadLink.link)).first() @@ -527,7 +527,7 @@ def api_comment(v): # queue up notification for parent author notify_users = set() - for x in g.db.query(Subscription.user_id).filter_by(submission_id=c.parent_submission).all(): + for x in g.db.query(Subscription.user_id).options(lazyload('*')).filter_by(submission_id=c.parent_submission).all(): notify_users.add(x[0]) if parent.author.id != v.id: notify_users.add(parent.author.id) @@ -537,7 +537,7 @@ def api_comment(v): for mention in mentions: username = mention["href"].split("@")[1] - user = g.db.query(User).filter_by(username=username).first() + user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first() if user: if v.any_block_exists(user): @@ -581,7 +581,7 @@ def api_comment(v): v.comment_count = v.comments.filter(Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count() g.db.add(v) - parent_post.comment_count = g.db.query(Comment).filter_by(parent_submission=parent_post.id).count() + parent_post.comment_count = g.db.query(Comment).options(lazyload('*')).filter_by(parent_submission=parent_post.id).count() g.db.add(parent_post) g.db.commit() @@ -650,7 +650,7 @@ def edit_comment(cid, v): fragment='') check_url = urlunparse(check_url) - badlink = g.db.query(BadLink).filter( + badlink = g.db.query(BadLink).options(lazyload('*')).filter( literal(check_url).contains( BadLink.link)).first() @@ -795,7 +795,7 @@ def edit_comment(cid, v): for mention in mentions: username = mention["href"].split("@")[1] - user = g.db.query(User).filter_by(username=username).first() + user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first() if user: if v.any_block_exists(user): @@ -819,7 +819,7 @@ def edit_comment(cid, v): @validate_formkey def delete_comment(cid, v): - c = g.db.query(Comment).filter_by(id=cid).first() + c = g.db.query(Comment).options(lazyload('*')).filter_by(id=cid).first() if not c: abort(404) @@ -842,7 +842,7 @@ def delete_comment(cid, v): @validate_formkey def undelete_comment(cid, v): - c = g.db.query(Comment).filter_by(id=cid).first() + c = g.db.query(Comment).options(lazyload('*')).filter_by(id=cid).first() if not c: abort(404) @@ -912,7 +912,7 @@ def unsave_comment(cid, v): comment=get_comment(cid) - save=g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=comment.id, type=2).first() + save=g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, submission_id=comment.id, type=2).first() if save: g.db.delete(save) diff --git a/files/routes/discord.py b/files/routes/discord.py index 5246274e9..3a0f20071 100644 --- a/files/routes/discord.py +++ b/files/routes/discord.py @@ -97,7 +97,7 @@ def discord_redirect(v): url=f"https://discord.com/api/guilds/{SERVER_ID}/members/{v.discord_id}" requests.delete(url, headers=headers) - if g.db.query(User).filter(User.id!=v.id, User.discord_id==x["id"]).first(): + if g.db.query(User).options(lazyload('*')).filter(User.id!=v.id, User.discord_id==x["id"]).first(): return render_template("message.html", title="Discord account already linked.", error="That Discord account is already in use by another user.", v=v) v.discord_id=x["id"] diff --git a/files/routes/front.py b/files/routes/front.py index b52047316..495c3a264 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -25,11 +25,11 @@ def notifications(v): modmail = request.args.get('modmail', False) posts = request.args.get('posts', False) if modmail and v.admin_level == 6: - comments = g.db.query(Comment).filter(Comment.sentto==0).order_by(Comment.created_utc.desc()).offset(25*(page-1)).limit(26).all() + comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.sentto==0).order_by(Comment.created_utc.desc()).offset(25*(page-1)).limit(26).all() next_exists = (len(comments) > 25) comments = comments[:25] elif messages: - comments = g.db.query(Comment).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None).order_by(Comment.created_utc.desc(), not_(Comment.child_comments.any())).offset(25*(page-1)).limit(26).all() + comments = g.db.query(Comment).options(lazyload('*')).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None).order_by(Comment.created_utc.desc(), not_(Comment.child_comments.any())).offset(25*(page-1)).limit(26).all() next_exists = (len(comments) > 25) comments = comments[:25] elif posts: @@ -209,8 +209,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' # g.db.add(vote) # try: g.db.flush() # except: g.db.rollback() - # post.upvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=1).count() - # post.downvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=-1).count() + # post.upvotes = g.db.query(Vote).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count() + # post.downvotes = g.db.query(Vote).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=-1).count() # post.views = post.views + random.randint(7,10) # g.db.add(post) @@ -218,7 +218,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' posts = posts[:25] - if page == 1: posts = g.db.query(Submission).filter_by(stickied=True).all() + posts + if page == 1: posts = g.db.query(Submission).options(lazyload('*')).filter_by(stickied=True).all() + posts if ids_only: posts = [x.id for x in posts] @@ -271,7 +271,7 @@ def front_all(v): @cache.memoize(timeout=86400) def changeloglist(v=None, sort="new", page=1 ,t="all", **kwargs): - posts = g.db.query(Submission).options(lazyload('*')).filter_by(is_banned=False, private=False,).filter(Submission.deleted_utc == 0) + posts = g.db.query(Submission).options(lazyload('*')).options(lazyload('*')).filter_by(is_banned=False, private=False,).filter(Submission.deleted_utc == 0) if v and v.admin_level == 0: blocking = g.db.query( @@ -373,7 +373,7 @@ def changelog(v): @auth_desired def random_post(v): - x = g.db.query(Submission).filter(Submission.deleted_utc == 0, Submission.is_banned == False) + x = g.db.query(Submission).options(lazyload('*')).filter(Submission.deleted_utc == 0, Submission.is_banned == False) total = x.count() n = random.randint(1, total - 2) @@ -384,11 +384,11 @@ def random_post(v): def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", **kwargs): posts = g.db.query(Submission).options(lazyload('*')) - cc_idlist = g.db.query(Submission.id).filter(Submission.club == True).subquery() + cc_idlist = g.db.query(Submission.id).options(lazyload('*')).filter(Submission.club == True).subquery() posts = posts.subquery() - comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.parent_submission.notin_(cc_idlist)) + comments = g.db.query(Comment).options(lazyload('*')).options(lazyload('*')).filter(Comment.parent_submission.notin_(cc_idlist)) if v and v.admin_level <= 3: blocking = g.db.query( diff --git a/files/routes/login.py b/files/routes/login.py index 4e5a0d9e5..230e371c4 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -32,9 +32,9 @@ def check_for_alts(current_id): if past_id == current_id: continue - check1 = g.db.query(Alt).filter_by( + check1 = g.db.query(Alt).options(lazyload('*')).filter_by( user1=current_id, user2=past_id).first() - check2 = g.db.query(Alt).filter_by( + check2 = g.db.query(Alt).options(lazyload('*')).filter_by( user1=past_id, user2=current_id).first() if not check1 and not check2: @@ -45,7 +45,7 @@ def check_for_alts(current_id): except BaseException: pass - otheralts = g.db.query(Alt).filter(or_(Alt.user1 == past_id, Alt.user2 == past_id, Alt.user1 == current_id, Alt.user2 == current_id)).all() + otheralts = g.db.query(Alt).options(lazyload('*')).filter(or_(Alt.user1 == past_id, Alt.user2 == past_id, Alt.user1 == current_id, Alt.user2 == current_id)).all() for a in otheralts: new_alt = Alt(user1=a.user1, user2=past_id) g.db.add(new_alt) @@ -70,7 +70,7 @@ def login_post(): if not username: abort(400) if "@" in username: - account = g.db.query(User).filter( + account = g.db.query(User).options(lazyload('*')).filter( User.email.ilike(username)).first() else: account = get_user(username, graceful=True) @@ -174,7 +174,7 @@ def sign_up_get(v): # check for referral in link ref = request.args.get("ref", None) if ref: - ref_user = g.db.query(User).filter(User.username.ilike(ref)).first() + ref_user = g.db.query(User).options(lazyload('*')).filter(User.username.ilike(ref)).first() else: ref_user = None @@ -247,7 +247,7 @@ def sign_up_post(v): args = {"error": error} if request.form.get("referred_by"): - user = g.db.query(User).filter_by( + user = g.db.query(User).options(lazyload('*')).filter_by( id=request.form.get("referred_by")).first() if user: args["ref"] = user.username @@ -318,7 +318,7 @@ def sign_up_post(v): lazyload('*')).filter_by(id=ref_id).first() if ref_user: # check self-setting badges - badge_types = g.db.query(BadgeDef).filter(BadgeDef.qualification_expr.isnot(None)).all() + badge_types = g.db.query(BadgeDef).options(lazyload('*')).filter(BadgeDef.qualification_expr.isnot(None)).all() for badge in badge_types: if eval(badge.qualification_expr, {}, {'v': ref_user}): if not ref_user.has_badge(badge.id): @@ -330,7 +330,7 @@ def sign_up_post(v): g.db.add(ref_user) - id_1 = g.db.query(User).filter_by(id=6).count() + id_1 = g.db.query(User).options(lazyload('*')).filter_by(id=6).count() users_count = g.db.query(User).count() #paranoid if id_1 == 0 and users_count < 6: admin_level=6 else: admin_level=0 @@ -344,9 +344,9 @@ def sign_up_post(v): email=email, created_utc=int(time.time()), referred_by=ref_id or None, - ban_evade = int(any([x.is_banned and not x.unban_utc for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x])), - agendaposter = any([x.agendaposter for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x]), - club_banned=any([x.club_banned for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x]) + ban_evade = int(any([x.is_banned and not x.unban_utc for x in g.db.query(User).options(lazyload('*')).filter(User.id.in_(tuple(session.get("history", [])))).all() if x])), + agendaposter = any([x.agendaposter for x in g.db.query(User).options(lazyload('*')).filter(User.id.in_(tuple(session.get("history", [])))).all() if x]), + club_banned=any([x.club_banned for x in g.db.query(User).options(lazyload('*')).filter(User.id.in_(tuple(session.get("history", [])))).all() if x]) ) g.db.add(new_user) @@ -391,7 +391,7 @@ def post_forgot(): email=email.replace("_","\_") - user = g.db.query(User).filter( + user = g.db.query(User).options(lazyload('*')).filter( User.username.ilike(username), User.email.ilike(email)).first() @@ -400,7 +400,7 @@ def post_forgot(): email=email.split('+')[0] email=email.replace('.','') email=f"{email}@gmail.com" - user = g.db.query(User).filter( + user = g.db.query(User).options(lazyload('*')).filter( User.username.ilike(username), User.email.ilike(email)).first() @@ -435,7 +435,7 @@ def get_reset(): title="Password reset link expired", error="That password reset link has expired.") - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() if not validate_hash(f"{user_id}+{timestamp}+forgot+{user.login_nonce}", token): abort(400) @@ -472,7 +472,7 @@ def post_reset(v): title="Password reset expired", error="That password reset form has expired.") - user = g.db.query(User).filter_by(id=user_id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() if not validate_hash(f"{user_id}+{timestamp}+reset+{user.login_nonce}", token): abort(400) diff --git a/files/routes/oauth.py b/files/routes/oauth.py index 30d315731..76c37208b 100644 --- a/files/routes/oauth.py +++ b/files/routes/oauth.py @@ -10,7 +10,7 @@ from files.__main__ import app @auth_required def authorize_prompt(v): client_id = request.args.get("client_id") - application = g.db.query(OauthApp).filter_by(client_id=client_id).first() + application = g.db.query(OauthApp).options(lazyload('*')).filter_by(client_id=client_id).first() if not application: return {"oauth_error": "Invalid `client_id`"}, 401 return render_template("oauth.html", v=v, application=application) @@ -21,7 +21,7 @@ def authorize_prompt(v): def authorize(v): client_id = request.form.get("client_id") - application = g.db.query(OauthApp).filter_by(client_id=client_id).first() + application = g.db.query(OauthApp).options(lazyload('*')).filter_by(client_id=client_id).first() if not application: return {"oauth_error": "Invalid `client_id`"}, 401 access_token = secrets.token_urlsafe(128)[:128] new_auth = ClientAuth( @@ -63,9 +63,9 @@ def request_api_keys(v): def delete_oauth_app(v, aid): aid = int(aid) - app = g.db.query(OauthApp).filter_by(id=aid).first() + app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first() - for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): + for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth) g.db.delete(app) @@ -81,7 +81,7 @@ def delete_oauth_app(v, aid): def edit_oauth_app(v, aid): aid = int(aid) - app = g.db.query(OauthApp).filter_by(id=aid).first() + app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first() app.redirect_uri = request.form.get('redirect_uri') app.app_name = request.form.get('name') @@ -99,7 +99,7 @@ def edit_oauth_app(v, aid): @validate_formkey def admin_app_approve(v, aid): - app = g.db.query(OauthApp).filter_by(id=aid).first() + app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first() user = app.author app.client_id = secrets.token_urlsafe(64)[:64] @@ -126,9 +126,9 @@ def admin_app_approve(v, aid): @validate_formkey def admin_app_revoke(v, aid): - app = g.db.query(OauthApp).filter_by(id=aid).first() + app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first() if app.id: - for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth) + for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth) g.db.flush() send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been revoked.") @@ -145,9 +145,9 @@ def admin_app_revoke(v, aid): @validate_formkey def admin_app_reject(v, aid): - app = g.db.query(OauthApp).filter_by(id=aid).first() + app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first() - for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth) + for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth) g.db.flush() send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been rejected.") @@ -229,7 +229,7 @@ def reroll_oauth_tokens(aid, v): aid = aid - a = g.db.query(OauthApp).filter_by(id=aid).first() + a = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first() if a.author_id != v.id: abort(403) diff --git a/files/routes/posts.py b/files/routes/posts.py index bab6c0318..94080eea2 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -103,15 +103,15 @@ def post_id(pid, anything=None, v=None): if post.club and not (v and v.paid_dues): abort(403) if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + votes = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id).subquery() blocking = v.blocking.subquery() blocked = v.blocked.subquery() if not (v and v.shadowbanned) and not (v and v.admin_level == 6): - shadowbanned = g.db.query(User.id).filter(User.shadowbanned == True).subquery() - comments = g.db.query(Comment).filter(Comment.author_id.notin_(shadowbanned)) + shadowbanned = g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned == True).subquery() + comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id.notin_(shadowbanned)) comments = g.db.query( Comment, @@ -121,7 +121,7 @@ def post_id(pid, anything=None, v=None): ) if not (v and v.shadowbanned) and not (v and v.admin_level == 6): - shadowbanned = g.db.query(User.id).filter(User.shadowbanned == True).subquery() + shadowbanned = g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned == True).subquery() comments = comments.filter(Comment.author_id.notin_(shadowbanned)) if v.admin_level >=4: @@ -170,9 +170,9 @@ def post_id(pid, anything=None, v=None): post.preloaded_comments = output else: - shadowbanned = g.db.query(User.id).filter(User.shadowbanned == True).subquery() + shadowbanned = g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned == True).subquery() - comments = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.author_id.notin_(shadowbanned)) + comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.parent_submission == post.id, Comment.author_id.notin_(shadowbanned)) if sort == "top": comments = sorted(comments.all(), key=lambda x: x.score, reverse=True) @@ -202,8 +202,8 @@ def post_id(pid, anything=None, v=None): # g.db.add(vote) # try: g.db.flush() # except: g.db.rollback() - # comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count() - # comment.downvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=-1).count() + # comment.upvotes = g.db.query(CommentVote).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count() + # comment.downvotes = g.db.query(CommentVote).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=-1).count() # g.db.add(comment) post.preloaded_comments = comments @@ -285,7 +285,7 @@ def edit_post(pid, v): fragment='') check_url = urlunparse(check_url) - badlink = g.db.query(BadLink).filter( + badlink = g.db.query(BadLink).options(lazyload('*')).filter( literal(check_url).contains( BadLink.link)).first() if badlink: @@ -379,7 +379,7 @@ def edit_post(pid, v): soup = BeautifulSoup(body_html, features="html.parser") for mention in soup.find_all("a", href=re.compile("^/@(\w+)")): username = mention["href"].split("@")[1] - user = g.db.query(User).filter_by(username=username).first() + user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user) for x in notify_users: send_notification(NOTIFICATIONS_ACCOUNT, x, f"@{v.username} has mentioned you: https://{site}{p.permalink}") @@ -622,7 +622,7 @@ def submit_post(v): url = url.replace(".png", "_d.png").replace(".jpg", "_d.jpg").replace(".jpeg", "_d.jpeg") if "_d." in url: url += "?maxwidth=9999" - repost = g.db.query(Submission).join(Submission.submission_aux).filter( + repost = g.db.query(Submission).join(Submission.submission_aux).options(lazyload('*')).filter( SubmissionAux.url.ilike(url), Submission.deleted_utc == 0, Submission.is_banned == False @@ -665,7 +665,7 @@ def submit_post(v): body = request.form.get("body", "") # check for duplicate - dup = g.db.query(Submission).join(Submission.submission_aux).filter( + dup = g.db.query(Submission).join(Submission.submission_aux).options(lazyload('*')).filter( Submission.author_id == v.id, Submission.deleted_utc == 0, @@ -843,7 +843,7 @@ def submit_post(v): fragment='') check_url = urlunparse(check_url) - badlink = g.db.query(BadLink).filter( + badlink = g.db.query(BadLink).options(lazyload('*')).filter( literal(check_url).contains( BadLink.link)).first() if badlink: @@ -966,7 +966,7 @@ def submit_post(v): soup = BeautifulSoup(body_html, features="html.parser") for mention in soup.find_all("a", href=re.compile("^/@(\w+)")): username = mention["href"].split("@")[1] - user = g.db.query(User).filter_by(username=username).first() + user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user) for x in notify_users: send_notification(NOTIFICATIONS_ACCOUNT, x, f"@{v.username} has mentioned you: https://{site}{new_post.permalink}") @@ -1150,7 +1150,7 @@ def undelete_post_pid(pid, v): @validate_formkey def toggle_comment_nsfw(cid, v): - comment = g.db.query(Comment).filter_by(id=cid).first() + comment = g.db.query(Comment).options(lazyload('*')).filter_by(id=cid).first() if not comment.author_id == v.id and not v.admin_level >= 3: abort(403) comment.over_18 = not comment.over_18 g.db.add(comment) @@ -1209,7 +1209,7 @@ def unsave_post(pid, v): post=get_post(pid) - save=g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=post.id, type=1).first() + save=g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id, type=1).first() if save: g.db.delete(save) diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 60ecc9e64..8b075216f 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -12,7 +12,7 @@ def api_flag_post(pid, v): post = get_post(pid) if v: - existing = g.db.query(Flag).filter_by(user_id=v.id, post_id=post.id).first() + existing = g.db.query(Flag).options(lazyload('*')).filter_by(user_id=v.id, post_id=post.id).first() if existing: return "", 409 @@ -43,7 +43,7 @@ def api_flag_comment(cid, v): comment = get_comment(cid) if v: - existing = g.db.query(CommentFlag).filter_by( + existing = g.db.query(CommentFlag).options(lazyload('*')).filter_by( user_id=v.id, comment_id=comment.id).first() if existing: return "", 409 @@ -75,9 +75,9 @@ def remove_report(report_fn, v): return {"error": "go outside"}, 403 if report_fn.startswith('c'): - report = g.db.query(CommentFlag).filter_by(id=int(report_fn.lstrip('c'))).first() + report = g.db.query(CommentFlag).options(lazyload('*')).filter_by(id=int(report_fn.lstrip('c'))).first() elif report_fn.startswith('p'): - report = g.db.query(Flag).filter_by(id=int(report_fn.lstrip('p'))).first() + report = g.db.query(Flag).options(lazyload('*')).filter_by(id=int(report_fn.lstrip('p'))).first() else: return {"error": "Invalid report ID"}, 400 diff --git a/files/routes/search.py b/files/routes/search.py index 7a826eb4e..483489d2f 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -150,7 +150,7 @@ def searchlisting(criteria, v=None, page=1, t="None", sort="top", b=None): def searchcommentlisting(criteria, v=None, page=1, t="None", sort="top"): - comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.parent_submission != None).join(Comment.comment_aux) + comments = g.db.query(Comment).options(lazyload('*')).options(lazyload('*')).filter(Comment.parent_submission != None).join(Comment.comment_aux) if 'q' in criteria: words=criteria['q'].split() @@ -278,7 +278,7 @@ def searchusers(v): term=term.replace('\\','') term=term.replace('_','\_') - users=g.db.query(User).filter(User.username.ilike(f'%{term}%')) + users=g.db.query(User).options(lazyload('*')).filter(User.username.ilike(f'%{term}%')) users=users.order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc()) diff --git a/files/routes/settings.py b/files/routes/settings.py index 3bf55d0b2..dc78ccb2a 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -417,7 +417,7 @@ def settings_security_post(v): return redirect("/settings/security?error=That email is already yours!") # check to see if email is in use - existing = g.db.query(User).filter(User.id != v.id, + existing = g.db.query(User).options(lazyload('*')).filter(User.id != v.id, func.lower(User.email) == new_email.lower()).first() if existing: return redirect("/settings/security?error=" + @@ -652,7 +652,7 @@ def settings_block_user(v): - existing = g.db.query(Notification).filter_by(blocksender=v.id, user_id=user.id).first() + existing = g.db.query(Notification).options(lazyload('*')).filter_by(blocksender=v.id, user_id=user.id).first() if not existing: send_block_notif(v.id, user.id, f"@{v.username} has blocked you!") if v.admin_level == 1: return {"message": f"@{user.username} banned!"} @@ -679,7 +679,7 @@ def settings_unblock_user(v): - existing = g.db.query(Notification).filter_by(unblocksender=v.id, user_id=user.id).first() + existing = g.db.query(Notification).options(lazyload('*')).filter_by(unblocksender=v.id, user_id=user.id).first() if not existing: send_unblock_notif(v.id, user.id, f"@{v.username} has unblocked you!") if v.admin_level == 1: return {"message": f"@{user.username} unbanned!"} @@ -759,7 +759,7 @@ def settings_name_change(v): v=v, error=f"Username `{new_name}` is already in use.") - v=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=v.id).first() + v=g.db.query(User).with_for_update().options(lazyload('*')).options(lazyload('*')).filter_by(id=v.id).first() v.username=new_name v.name_changed_utc=int(time.time()) @@ -778,7 +778,7 @@ def settings_name_change(v): def settings_song_change(v): song=request.form.get("song").strip() - if song == "" and v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: + if song == "" and v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).options(lazyload('*')).filter_by(song=v.song).count() == 1: os.remove(f"/songs/{v.song}.mp3") v.song=None g.db.add(v) @@ -821,7 +821,7 @@ def settings_song_change(v): error=f"Duration of the video must not exceed 10 minutes.") - if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: + if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).options(lazyload('*')).filter_by(song=v.song).count() == 1: os.remove(f"/songs/{v.song}.mp3") ydl_opts = { diff --git a/files/routes/static.py b/files/routes/static.py index 8c3226035..f90a548db 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -33,28 +33,28 @@ def participation_stats(v): day = now - 86400 data = {"valid_users": g.db.query(User).count(), - "private_users": g.db.query(User).filter_by(is_private=True).count(), - "banned_users": g.db.query(User).filter(User.is_banned > 0).count(), - "verified_email_users": g.db.query(User).filter_by(is_activated=True).count(), + "private_users": g.db.query(User).options(lazyload('*')).filter_by(is_private=True).count(), + "banned_users": g.db.query(User).options(lazyload('*')).filter(User.is_banned > 0).count(), + "verified_email_users": g.db.query(User).options(lazyload('*')).filter_by(is_activated=True).count(), "total_coins": g.db.query(func.sum(User.coins)).scalar(), - "signups_last_24h": g.db.query(User).filter(User.created_utc > day).count(), + "signups_last_24h": g.db.query(User).options(lazyload('*')).filter(User.created_utc > day).count(), "total_posts": g.db.query(Submission).count(), "posting_users": g.db.query(Submission.author_id).distinct().count(), - "listed_posts": g.db.query(Submission).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(), - "removed_posts": g.db.query(Submission).filter_by(is_banned=True).count(), - "deleted_posts": g.db.query(Submission).filter(Submission.deleted_utc > 0).count(), - "posts_last_24h": g.db.query(Submission).filter(Submission.created_utc > day).count(), + "listed_posts": g.db.query(Submission).options(lazyload('*')).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(), + "removed_posts": g.db.query(Submission).options(lazyload('*')).filter_by(is_banned=True).count(), + "deleted_posts": g.db.query(Submission).options(lazyload('*')).filter(Submission.deleted_utc > 0).count(), + "posts_last_24h": g.db.query(Submission).options(lazyload('*')).filter(Submission.created_utc > day).count(), "total_comments": g.db.query(Comment).count(), "commenting_users": g.db.query(Comment.author_id).distinct().count(), - "removed_comments": g.db.query(Comment).filter_by(is_banned=True).count(), - "deleted_comments": g.db.query(Comment).filter(Comment.deleted_utc>0).count(), - "comments_last_24h": g.db.query(Comment).filter(Comment.created_utc > day).count(), + "removed_comments": g.db.query(Comment).options(lazyload('*')).filter_by(is_banned=True).count(), + "deleted_comments": g.db.query(Comment).options(lazyload('*')).filter(Comment.deleted_utc>0).count(), + "comments_last_24h": g.db.query(Comment).options(lazyload('*')).filter(Comment.created_utc > day).count(), "post_votes": g.db.query(Vote).count(), "post_voting_users": g.db.query(Vote.user_id).distinct().count(), "comment_votes": g.db.query(CommentVote).count(), "comment_voting_users": g.db.query(CommentVote.user_id).distinct().count(), "total_awards": g.db.query(AwardRelationship).count(), - "awards_given": g.db.query(AwardRelationship).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count() + "awards_given": g.db.query(AwardRelationship).options(lazyload('*')).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count() } @@ -89,7 +89,7 @@ def patrons(v): @app.get("/badmins") @auth_desired def admins(v): - admins = g.db.query(User).filter_by(admin_level=6).order_by(User.coins.desc()).all() + admins = g.db.query(User).options(lazyload('*')).filter_by(admin_level=6).order_by(User.coins.desc()).all() return render_template("admins.html", v=v, admins=admins) @app.get("/log") @@ -100,7 +100,7 @@ def log(v): page=int(request.args.get("page",1)) if v and v.admin_level == 6: actions = g.db.query(ModAction).order_by(ModAction.id.desc()).offset(25 * (page - 1)).limit(26).all() - else: actions=g.db.query(ModAction).filter(ModAction.kind!="shadowban", ModAction.kind!="unshadowban", ModAction.kind!="club", ModAction.kind!="unclub").order_by(ModAction.id.desc()).offset(25*(page-1)).limit(26).all() + else: actions=g.db.query(ModAction).options(lazyload('*')).filter(ModAction.kind!="shadowban", ModAction.kind!="unshadowban", ModAction.kind!="club", ModAction.kind!="unclub").order_by(ModAction.id.desc()).offset(25*(page-1)).limit(26).all() next_exists=len(actions)==26 actions=actions[:25] @@ -116,7 +116,7 @@ def log_item(id, v): try: id = int(id, 36) except: abort(404) - action=g.db.query(ModAction).filter_by(id=id).first() + action=g.db.query(ModAction).options(lazyload('*')).filter_by(id=id).first() if not action: abort(404) @@ -228,7 +228,7 @@ def blocks(v): def banned(v): - users = [x for x in g.db.query(User).filter(User.is_banned > 0, User.unban_utc == 0).all()] + users = [x for x in g.db.query(User).options(lazyload('*')).filter(User.is_banned > 0, User.unban_utc == 0).all()] return render_template("banned.html", v=v, users=users) @app.get("/formatting") diff --git a/files/routes/users.py b/files/routes/users.py index cdd514405..c7314a824 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -77,16 +77,16 @@ def steal(v): @app.get("/rentoids") @auth_desired def rentoids(v): - users = g.db.query(User).filter(User.rent_utc > 0).all() + users = g.db.query(User).options(lazyload('*')).filter(User.rent_utc > 0).all() return render_template("rentoids.html", v=v, users=users) @app.get("/thiefs") @auth_desired def thiefs(v): - successful = g.db.query(User).filter(User.steal_utc > 0).all() - failed = g.db.query(User).filter(User.fail_utc > 0).all() - failed2 = g.db.query(User).filter(User.fail2_utc > 0).all() + successful = g.db.query(User).options(lazyload('*')).filter(User.steal_utc > 0).all() + failed = g.db.query(User).options(lazyload('*')).filter(User.fail_utc > 0).all() + failed2 = g.db.query(User).options(lazyload('*')).filter(User.fail2_utc > 0).all() return render_template("thiefs.html", v=v, successful=successful, failed=failed, failed2=failed2) @@ -175,7 +175,7 @@ def get_profilecss(username): def songs(id): try: id = int(id) except: return "", 400 - user = g.db.query(User).filter_by(id=id).first() + user = g.db.query(User).options(lazyload('*')).filter_by(id=id).first() return redirect(f"/song/{user.song}.mp3") @app.get("/song/") @@ -196,7 +196,7 @@ def subscribe(v, post_id): @app.post("/unsubscribe/") @auth_required def unsubscribe(v, post_id): - sub=g.db.query(Subscription).filter_by(user_id=v.id, submission_id=post_id).first() + sub=g.db.query(Subscription).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post_id).first() g.db.delete(sub) g.db.commit() return {"message": "Post unsubscribed!"} @@ -214,7 +214,7 @@ def message2(v, username): message = message.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") # check existing - existing = g.db.query(Comment).join(CommentAux).filter(Comment.author_id == v.id, + existing = g.db.query(Comment).join(CommentAux).options(lazyload('*')).filter(Comment.author_id == v.id, Comment.sentto == user.id, CommentAux.body == message, ).options(contains_eager(Comment.comment_aux)).first() @@ -254,7 +254,7 @@ def messagereply(v): message = message.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") # check existing - existing = g.db.query(Comment).join(CommentAux).filter(Comment.author_id == v.id, + existing = g.db.query(Comment).join(CommentAux).options(lazyload('*')).filter(Comment.author_id == v.id, Comment.sentto == user.id, CommentAux.body == message, ).options(contains_eager(Comment.comment_aux)).first() @@ -382,7 +382,7 @@ def u_username(username, v=None): # viewers if v and u.id != v.id: - view = g.db.query(ViewerRelationship).filter( + view = g.db.query(ViewerRelationship).options(lazyload('*')).filter( and_( ViewerRelationship.viewer_id == v.id, ViewerRelationship.user_id == u.id @@ -434,7 +434,7 @@ def u_username(username, v=None): # If page 1, check for sticky if page == 1: sticky = [] - sticky = g.db.query(Submission).filter_by(is_pinned=True, author_id=u.id).all() + sticky = g.db.query(Submission).options(lazyload('*')).filter_by(is_pinned=True, author_id=u.id).all() if sticky: for p in sticky: ids = [p.id] + ids @@ -595,15 +595,15 @@ def follow_user(username, v): if target.id==v.id: return {"error": "You can't follow yourself!"}, 400 # check for existing follow - if g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first(): return {"message": "User followed!"} + if g.db.query(Follow).options(lazyload('*')).filter_by(user_id=v.id, target_id=target.id).first(): return {"message": "User followed!"} new_follow = Follow(user_id=v.id, target_id=target.id) g.db.add(new_follow) - target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id).count() + target.stored_subscriber_count = g.db.query(Follow).options(lazyload('*')).filter_by(target_id=target.id).count() g.db.add(target) - existing = g.db.query(Notification).filter_by(followsender=v.id, user_id=target.id).first() + existing = g.db.query(Notification).options(lazyload('*')).filter_by(followsender=v.id, user_id=target.id).first() if not existing: send_follow_notif(v.id, target.id, f"@{v.username} has followed you!") g.db.commit() @@ -617,15 +617,15 @@ def unfollow_user(username, v): target = get_user(username) # check for existing follow - follow = g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first() + follow = g.db.query(Follow).options(lazyload('*')).filter_by(user_id=v.id, target_id=target.id).first() if not follow: return {"message": "User unfollowed!"} g.db.delete(follow) - target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id).count() + target.stored_subscriber_count = g.db.query(Follow).options(lazyload('*')).filter_by(target_id=target.id).count() g.db.add(target) - existing = g.db.query(Notification).filter_by(unfollowsender=v.id, user_id=target.id).first() + existing = g.db.query(Notification).options(lazyload('*')).filter_by(unfollowsender=v.id, user_id=target.id).first() if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has unfollowed you!") g.db.commit() diff --git a/files/routes/votes.py b/files/routes/votes.py index 3be315e7a..fd11176a2 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -69,7 +69,7 @@ def api_vote_post(post_id, new, v): post = get_post(post_id) # check for existing vote - existing = g.db.query(Vote).filter_by(user_id=v.id, submission_id=post.id).first() + existing = g.db.query(Vote).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id).first() if existing and existing.vote_type == new: return "", 204 @@ -96,8 +96,8 @@ def api_vote_post(post_id, new, v): ) g.db.add(vote) - post.upvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=1).count() - post.downvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=-1).count() + post.upvotes = g.db.query(Vote).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count() + post.downvotes = g.db.query(Vote).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=-1).count() g.db.add(post) g.db.commit() return "", 204 @@ -121,7 +121,7 @@ def api_vote_comment(comment_id, new, v): comment = get_comment(comment_id) # check for existing vote - existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).first() + existing = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first() if existing and existing.vote_type == new: return "", 204 @@ -149,8 +149,8 @@ def api_vote_comment(comment_id, new, v): g.db.add(vote) - comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count() - comment.downvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=-1).count() + comment.upvotes = g.db.query(CommentVote).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count() + comment.downvotes = g.db.query(CommentVote).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=-1).count() g.db.add(comment) g.db.commit() return "", 204 \ No newline at end of file From f48370ef9c853d0b607a585849e4a540d6e72108 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:30:47 +0200 Subject: [PATCH 20/64] fd --- files/__main__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 7f2c77806..300759570 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -9,7 +9,7 @@ from flask_compress import Compress from flask_limiter.util import get_ipaddr from flaskext.markdown import Markdown from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import sessionmaker, scoped_session, Query as _Query +from sqlalchemy.orm import lazyload, sessionmaker, scoped_session, Query as _Query from sqlalchemy import * from sqlalchemy.pool import QueuePool import redis @@ -84,8 +84,7 @@ _engine=create_engine( app.config['DATABASE_URL'], poolclass=QueuePool, pool_size=int(environ.get("PG_POOL_SIZE",10)), - pool_use_lifo=True, - echo=True + pool_use_lifo=True ) def retry(f): From 88b68327eddc2b65dab0a9bdbde550b8491731aa Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:34:36 +0200 Subject: [PATCH 21/64] df --- files/__main__.py | 2 +- files/helpers/filters.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/files/__main__.py b/files/__main__.py index 300759570..73aec4224 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -9,7 +9,7 @@ from flask_compress import Compress from flask_limiter.util import get_ipaddr from flaskext.markdown import Markdown from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import lazyload, sessionmaker, scoped_session, Query as _Query +from sqlalchemy.orm import sessionmaker, scoped_session, Query as _Query from sqlalchemy import * from sqlalchemy.pool import QueuePool import redis diff --git a/files/helpers/filters.py b/files/helpers/filters.py index e4c1698f2..d6f5658ef 100644 --- a/files/helpers/filters.py +++ b/files/helpers/filters.py @@ -2,6 +2,7 @@ from bs4 import BeautifulSoup from flask import * from urllib.parse import urlparse from files.classes import BannedDomain +from sqlalchemy.orm import lazyload def filter_comment_html(html_text): From fdeb1e997bc32fdf7bc4bc0a419ef1623db950f4 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:38:59 +0200 Subject: [PATCH 22/64] fd --- files/routes/front.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/files/routes/front.py b/files/routes/front.py index 495c3a264..69e69e5fd 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -10,12 +10,6 @@ defaulttimefilter = environ.get("DEFAULT_TIME_FILTER", "all").strip() def slash_post(): return redirect("/") -@app.get("/testing") -def testing(): - notifications = g.db.query(Notification).options(lazyload('*')).join(Notification.comment).limit(26) - notifications2 = g.db.query(Notification).join(Notification.comment).limit(26) - return "sex" - @app.get("/notifications") @auth_required def notifications(v): From 06669e9d4eefa28b68997a9bfae91d5318c483cd Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 10:55:55 +0200 Subject: [PATCH 23/64] df --- files/helpers/alerts.py | 15 ++++++--------- files/helpers/wrappers.py | 3 +-- files/mail/mail.py | 1 + files/routes/admin.py | 26 ++++++++++++-------------- files/routes/awards.py | 3 +-- files/routes/oauth.py | 4 +--- files/routes/posts.py | 17 ++++++++--------- files/routes/users.py | 3 ++- 8 files changed, 32 insertions(+), 40 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index bc81e63ca..dd81fc493 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -7,7 +7,7 @@ from .sanitize import * from .const import * -def send_notification(vid, user, text, db=None): +def send_notification(vid, user, text): # for when working outside request context if isinstance(user, int): @@ -15,9 +15,6 @@ def send_notification(vid, user, text, db=None): else: uid = user.id - if not db: - db = g.db - text = text.replace('r/', 'r\/').replace('u/', 'u\/') text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") text_html = CustomRenderer().render(mistletoe.Document(text)) @@ -28,20 +25,20 @@ def send_notification(vid, user, text, db=None): parent_submission=None, distinguish_level=6, ) - db.add(new_comment) + g.db.add(new_comment) - db.flush() + g.db.flush() new_aux = CommentAux(id=new_comment.id, body=text, body_html=text_html, ) - db.add(new_aux) + g.db.add(new_aux) notif = Notification(comment_id=new_comment.id, user_id=uid) - db.add(notif) - db.commit() + g.db.add(notif) + g.db.commit() def send_follow_notif(vid, user, text): diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 507adee0c..8e31ef2c0 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -92,15 +92,14 @@ def check_ban_evade(v): g.db.add(ma) except: pass - g.db.flush() try: abort(403) except Exception as e: print(e) else: v.ban_evade +=1 g.db.add(v) - g.db.flush() + g.db.commit() diff --git a/files/mail/mail.py b/files/mail/mail.py index f0ca51c20..ac5f5291b 100644 --- a/files/mail/mail.py +++ b/files/mail/mail.py @@ -96,5 +96,6 @@ def activate(v): g.db.add(mail_badge) g.db.add(user) + g.db.commit() return render_template("message_success.html", v=v, title="Email verified.", message=f"Your email {email} has been verified. Thank you.") diff --git a/files/routes/admin.py b/files/routes/admin.py index 12baabaec..40475a8f0 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -42,7 +42,7 @@ def revert_actions(v, username): for user in users: user.unban() - g.db.commit() + g.db.commit() return {"message": "Admin actions reverted!"} @app.post("/@/club_allow") @@ -97,7 +97,7 @@ def make_admin(v, username): if not user: abort(404) user.admin_level = 6 g.db.add(user) - g.db.commit() + g.db.commit() return {"message": "User has been made admin!"} @@ -109,7 +109,7 @@ def remove_admin(v, username): if not user: abort(404) user.admin_level = 0 g.db.add(user) - g.db.commit() + g.db.commit() return {"message": "Admin removed!"} @@ -121,7 +121,7 @@ def make_fake_admin(v, username): if not user: abort(404) user.admin_level = 1 g.db.add(user) - g.db.commit() + g.db.commit() return {"message": "User has been made fake admin!"} @@ -133,7 +133,7 @@ def remove_fake_admin(v, username): if not user: abort(404) user.admin_level = 0 g.db.add(user) - g.db.commit() + g.db.commit() return {"message": "Fake admin removed!"} @@ -436,7 +436,7 @@ def badge_grant_post(v): g.db.add(user) - g.db.commit() + g.db.commit() return redirect("/admin/badge_grant") @@ -720,7 +720,6 @@ def agendaposter(user_id, v): note = note ) g.db.add(ma) - g.db.flush() if user.agendaposter: if not user.has_badge(26): @@ -891,8 +890,6 @@ def ban_user(user_id, v): ) g.db.add(ma) - g.db.commit() - if 'reason' in request.args: if reason.startswith("/post/"): post = reason.split("/post/")[1].split("/")[0] @@ -904,8 +901,11 @@ def ban_user(user_id, v): comment = get_comment(comment) comment.bannedfor = True g.db.add(comment) + g.db.commit() return {"message": f"@{user.username} was banned!"} - else: return redirect(user.url) + else: + g.db.commit() + return redirect(user.url) @app.post("/unban_user/") @@ -937,10 +937,8 @@ def unban_user(user_id, v): g.db.commit() - if "@" in request.referrer: - return redirect(user.url) - else: - return {"message": f"@{user.username} was unbanned!"} + if "@" in request.referrer: return redirect(user.url) + else: return {"message": f"@{user.username} was unbanned!"} @app.post("/ban_post/") @admin_level_required(3) diff --git a/files/routes/awards.py b/files/routes/awards.py index 9a6034194..f6d103ff5 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -252,8 +252,7 @@ def award_post(pid, v): send_notification(NOTIFICATIONS_ACCOUNT, post.author, msg) - if kind in ACTIONS: - ACTIONS[kind](post=post) + if kind in ACTIONS: ACTIONS[kind](post=post) post.author.received_award_count += 1 g.db.add(post.author) diff --git a/files/routes/oauth.py b/files/routes/oauth.py index 76c37208b..7704da789 100644 --- a/files/routes/oauth.py +++ b/files/routes/oauth.py @@ -130,12 +130,11 @@ def admin_app_revoke(v, aid): if app.id: for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth) - g.db.flush() send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been revoked.") g.db.delete(app) - g.db.commit() + g.db.commit() return {"message": f"App revoked"} @@ -149,7 +148,6 @@ def admin_app_reject(v, aid): for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth) - g.db.flush() send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been rejected.") g.db.delete(app) diff --git a/files/routes/posts.py b/files/routes/posts.py index 94080eea2..8d21c6b3b 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -448,7 +448,7 @@ def filter_title(title): IMGUR_KEY = environ.get("IMGUR_KEY", "").strip() -def check_processing_thread(v, post, link, db): +def check_processing_thread(v, post, link): image_id = link.split('/')[-1].rstrip('.mp4') headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} @@ -463,16 +463,15 @@ def check_processing_thread(v, post, link, db): status = req.json()['data']['processing']['status'] if status == 'completed': post.processing = False - db.add(post) + g.db.add(post) send_notification( NOTIFICATIONS_ACCOUNT, v, - f"Your video has finished processing and your [post](/post/{post.id}) is now live.", - db=db + f"Your video has finished processing and your [post](/post/{post.id}) is now live." ) - db.commit() + g.db.commit() break # just in case elif status == 'failed': @@ -933,7 +932,7 @@ def submit_post(v): post_url += 'mp4' new_post.url = post_url new_post.processing = True - gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db) + gevent.spawn(check_processing_thread, v.id, new_post, post_url) except UploadException as e: if request.headers.get("Authorization"): return { @@ -1211,8 +1210,8 @@ def unsave_post(pid, v): save=g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id, type=1).first() - if save: g.db.delete(save) - - g.db.commit() + if save: + g.db.delete(save) + g.db.commit() return {"message": "Post unsaved!"} diff --git a/files/routes/users.py b/files/routes/users.py index c7314a824..89b651575 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -131,11 +131,12 @@ def transfer_coins(v, username): receiver.coins += amount g.db.add(receiver) g.db.add(v) - g.db.commit() transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['COINS_NAME']}!" send_notification(NOTIFICATIONS_ACCOUNT, receiver, transfer_message) + g.db.commit() + return {"message": f"{app.config['COINS_NAME']} transferred!"} From c05dd071e2d4052061620d416b701a2b80f6833f Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 11:12:54 +0200 Subject: [PATCH 24/64] fd --- files/__main__.py | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 73aec4224..dd011542f 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -83,7 +83,7 @@ limiter = Limiter( _engine=create_engine( app.config['DATABASE_URL'], poolclass=QueuePool, - pool_size=int(environ.get("PG_POOL_SIZE",10)), + pool_size=197, pool_use_lifo=True ) diff --git a/requirements.txt b/requirements.txt index fe3e4319d..489932b05 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,7 @@ pyotp qrcode redis requests -SQLAlchemy==1.3.19 +SQLAlchemy psycopg2-binary pusher_push_notifications youtube-dl From 6fef2940667bd7f501f762ea2d8cbc5dedd9c2cd Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 11:28:19 +0200 Subject: [PATCH 25/64] fd --- files/helpers/alerts.py | 1 - 1 file changed, 1 deletion(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index dd81fc493..e95a99f76 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -38,7 +38,6 @@ def send_notification(vid, user, text): notif = Notification(comment_id=new_comment.id, user_id=uid) g.db.add(notif) - g.db.commit() def send_follow_notif(vid, user, text): From ec6d7020b602fef4ff5da962d6fecc3a44cc495e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 11:33:56 +0200 Subject: [PATCH 26/64] fd --- files/routes/awards.py | 1 + files/templates/shop.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/files/routes/awards.py b/files/routes/awards.py index f6d103ff5..635e3eee8 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -7,6 +7,7 @@ from files.classes.award import * from flask import g, request @app.get("/shop") +@app.get("/settings/shop") @auth_required def shop(v): if site_name == "Drama": diff --git a/files/templates/shop.html b/files/templates/shop.html index 690382d34..70970420c 100644 --- a/files/templates/shop.html +++ b/files/templates/shop.html @@ -1,4 +1,4 @@ -{% extends "default.html" %} +{% extends "settings.html" %} {% block title %} Shop From 5e0a5950471e0203342dcb2b30532762ac779180 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 11:37:13 +0200 Subject: [PATCH 27/64] fd --- files/templates/settings.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/files/templates/settings.html b/files/templates/settings.html index 927795b15..d59417687 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -156,6 +156,9 @@ + @@ -186,6 +189,9 @@ + From 45f861e424fc525b924942c18594bc81609a152b Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 11:38:53 +0200 Subject: [PATCH 28/64] fd --- files/templates/settings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/templates/settings.html b/files/templates/settings.html index d59417687..b30bccb51 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -157,7 +157,7 @@ Apps From a4d1a5e68f36c4f90369b440d6ef17012006462c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 11:42:08 +0200 Subject: [PATCH 29/64] fd --- files/templates/emoji_modal.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/files/templates/emoji_modal.html b/files/templates/emoji_modal.html index 601deb7d2..2c4355d71 100644 --- a/files/templates/emoji_modal.html +++ b/files/templates/emoji_modal.html @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/files/templates/index.html b/files/templates/index.html deleted file mode 100644 index 7bc1312cf..000000000 --- a/files/templates/index.html +++ /dev/null @@ -1,8 +0,0 @@ - -
-

{{greeting}}

-

[[ greeting ]]

-
- - - \ No newline at end of file diff --git a/files/templates/shop.html b/files/templates/settings_shop.html similarity index 100% rename from files/templates/shop.html rename to files/templates/settings_shop.html From 689559425df11cd8837f080474aa06ff5e90a6d9 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 13:19:06 +0200 Subject: [PATCH 34/64] fdfd --- files/assets/js/bundle.js | 795 ++++++++++++++++++++++++++--------- files/assets/js/bundle2.js | 797 +++++++++--------------------------- files/templates/submit.html | 2 +- 3 files changed, 792 insertions(+), 802 deletions(-) diff --git a/files/assets/js/bundle.js b/files/assets/js/bundle.js index c5e7d31b6..75976f718 100644 --- a/files/assets/js/bundle.js +++ b/files/assets/js/bundle.js @@ -1,12 +1,8 @@ (function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document); -(function (marked) { +(function () { 'use strict'; - function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } - - var marked__default = /*#__PURE__*/_interopDefaultLegacy(marked); - function noop() { } function add_location(element, file, line, column, char) { element.__svelte_meta = { @@ -31,12 +27,21 @@ function is_empty(obj) { return Object.keys(obj).length === 0; } + function append(target, node) { + target.appendChild(node); + } function insert(target, node, anchor) { target.insertBefore(node, anchor || null); } function detach(node) { node.parentNode.removeChild(node); } + function destroy_each(iterations, detaching) { + for (let i = 0; i < iterations.length; i += 1) { + if (iterations[i]) + iterations[i].d(detaching); + } + } function element(name) { return document.createElement(name); } @@ -68,44 +73,14 @@ function set_style(node, key, value, important) { node.style.setProperty(key, value, important ? 'important' : ''); } + function toggle_class(element, name, toggle) { + element.classList[toggle ? 'add' : 'remove'](name); + } function custom_event(type, detail, bubbles = false) { const e = document.createEvent('CustomEvent'); e.initCustomEvent(type, bubbles, false, detail); return e; } - class HtmlTag { - constructor() { - this.e = this.n = null; - } - c(html) { - this.h(html); - } - m(html, target, anchor = null) { - if (!this.e) { - this.e = element(target.nodeName); - this.t = target; - this.c(html); - } - this.i(anchor); - } - h(html) { - this.e.innerHTML = html; - this.n = Array.from(this.e.childNodes); - } - i(anchor) { - for (let i = 0; i < this.n.length; i += 1) { - insert(this.t, this.n[i], anchor); - } - } - p(html) { - this.d(); - this.h(html); - this.i(this.a); - } - d() { - this.n.forEach(detach); - } - } let current_component; function set_current_component(component) { @@ -311,6 +286,10 @@ function dispatch_dev(type, detail) { document.dispatchEvent(custom_event(type, Object.assign({ version: '3.42.6' }, detail), true)); } + function append_dev(target, node) { + dispatch_dev('SvelteDOMInsert', { target, node }); + append(target, node); + } function insert_dev(target, node, anchor) { dispatch_dev('SvelteDOMInsert', { target, node, anchor }); insert(target, node, anchor); @@ -339,6 +318,22 @@ else dispatch_dev('SvelteDOMSetAttribute', { node, attribute, value }); } + function set_data_dev(text, data) { + data = '' + data; + if (text.wholeText === data) + return; + dispatch_dev('SvelteDOMSetData', { node: text, data }); + text.data = data; + } + function validate_each_argument(arg) { + if (typeof arg !== 'string' && !(arg && typeof arg === 'object' && 'length' in arg)) { + let msg = '{#each} only iterates over array-like objects.'; + if (typeof Symbol === 'function' && arg && Symbol.iterator in arg) { + msg += ' You can use a spread to convert this iterable into an array.'; + } + throw new Error(msg); + } + } function validate_slots(name, slot, keys) { for (const slot_key of Object.keys(slot)) { if (!~keys.indexOf(slot_key)) { @@ -367,48 +362,100 @@ } /* src\App.svelte generated by Svelte v3.42.6 */ + const file = "src\\App.svelte"; - // (27:1) {:else} - function create_else_block(ctx) { - let t; - - const block = { - c: function create() { - t = text("Show preview"); - }, - m: function mount(target, anchor) { - insert_dev(target, t, anchor); - }, - d: function destroy(detaching) { - if (detaching) detach_dev(t); - } - }; - - dispatch_dev("SvelteRegisterBlock", { - block, - id: create_else_block.name, - type: "else", - source: "(27:1) {:else}", - ctx - }); - - return block; + function get_each_context(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[8] = list[i]; + child_ctx[10] = i; + return child_ctx; } - // (25:1) {#if show_preview} + // (55:4) {#if loaded} function create_if_block_1(ctx) { + let form; + let div; let t; + let each_value = /*awards*/ ctx[1]; + validate_each_argument(each_value); + let each_blocks = []; + + for (let i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i)); + } + + let if_block = /*picked*/ ctx[3] != null && create_if_block_2(ctx); const block = { c: function create() { - t = text("Hide preview"); + form = element("form"); + div = element("div"); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + t = space(); + if (if_block) if_block.c(); + attr_dev(div, "class", "card-columns awards-wrapper svelte-13ovg7j"); + add_location(div, file, 56, 6, 1272); + attr_dev(form, "class", "pt-3 pb-0"); + add_location(form, file, 55, 5, 1240); }, m: function mount(target, anchor) { - insert_dev(target, t, anchor); + insert_dev(target, form, anchor); + append_dev(form, div); + + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(div, null); + } + + append_dev(form, t); + if (if_block) if_block.m(form, null); + }, + p: function update(ctx, dirty) { + if (dirty & /*awards, picked*/ 10) { + each_value = /*awards*/ ctx[1]; + validate_each_argument(each_value); + let i; + + for (i = 0; i < each_value.length; i += 1) { + const child_ctx = get_each_context(ctx, each_value, i); + + if (each_blocks[i]) { + each_blocks[i].p(child_ctx, dirty); + } else { + each_blocks[i] = create_each_block(child_ctx); + each_blocks[i].c(); + each_blocks[i].m(div, null); + } + } + + for (; i < each_blocks.length; i += 1) { + each_blocks[i].d(1); + } + + each_blocks.length = each_value.length; + } + + if (/*picked*/ ctx[3] != null) { + if (if_block) { + if_block.p(ctx, dirty); + } else { + if_block = create_if_block_2(ctx); + if_block.c(); + if_block.m(form, null); + } + } else if (if_block) { + if_block.d(1); + if_block = null; + } }, d: function destroy(detaching) { - if (detaching) detach_dev(t); + if (detaching) detach_dev(form); + destroy_each(each_blocks, detaching); + if (if_block) if_block.d(); } }; @@ -416,35 +463,346 @@ block, id: create_if_block_1.name, type: "if", - source: "(25:1) {#if show_preview}", + source: "(55:4) {#if loaded}", ctx }); return block; } - // (34:0) {#if show_preview} - function create_if_block(ctx) { - let html_tag; - let raw_value = marked__default['default'](marking(/*text*/ ctx[0])) + ""; - let html_anchor; + // (59:8) {#if award.owned < 1} + function create_if_block_3(ctx) { + let input; + let t0; + let label; + let i; + let i_class_value; + let br; + let t1; + let span1; + let t2_value = /*award*/ ctx[8].title + ""; + let t2; + let t3; + let span0; + let t4_value = /*award*/ ctx[8].owned + ""; + let t4; + let t5; + let t6; + let mounted; + let dispose; const block = { c: function create() { - html_tag = new HtmlTag(); - html_anchor = empty(); - html_tag.a = html_anchor; + input = element("input"); + t0 = space(); + label = element("label"); + i = element("i"); + br = element("br"); + t1 = space(); + span1 = element("span"); + t2 = text(t2_value); + t3 = text("/span>\r\n\t\t\t\t\t\t\t\t\t\t"); + span0 = element("span"); + t4 = text(t4_value); + t5 = text(" owned"); + t6 = space(); + attr_dev(input, "type", "radio"); + attr_dev(input, "id", /*index*/ ctx[10]); + attr_dev(input, "class", "svelte-13ovg7j"); + toggle_class(input, "disabled", /*award*/ ctx[8].owned < 1); + add_location(input, file, 59, 9, 1394); + attr_dev(i, "class", i_class_value = "" + (/*award*/ ctx[8].icon + " " + /*award*/ ctx[8].color + " svelte-13ovg7j")); + add_location(i, file, 61, 10, 1574); + add_location(br, file, 61, 52, 1616); + attr_dev(span0, "class", "text-muted"); + add_location(span0, file, 63, 10, 1736); + attr_dev(span1, "class", "d-block pt-2"); + set_style(span1, "font-weight", "bold"); + set_style(span1, "font-size", "14px"); + add_location(span1, file, 62, 10, 1634); + attr_dev(label, "class", "card svelte-13ovg7j"); + attr_dev(label, "for", /*index*/ ctx[10]); + toggle_class(label, "disabled", /*award*/ ctx[8].owned < 1); + add_location(label, file, 60, 9, 1493); }, m: function mount(target, anchor) { - html_tag.m(raw_value, target, anchor); - insert_dev(target, html_anchor, anchor); + insert_dev(target, input, anchor); + set_input_value(input, /*picked*/ ctx[3]); + insert_dev(target, t0, anchor); + insert_dev(target, label, anchor); + append_dev(label, i); + append_dev(label, br); + append_dev(label, t1); + append_dev(label, span1); + append_dev(span1, t2); + append_dev(span1, t3); + append_dev(span1, span0); + append_dev(span0, t4); + append_dev(span0, t5); + append_dev(span1, t6); + + if (!mounted) { + dispose = listen_dev(input, "change", /*input_change_handler*/ ctx[6]); + mounted = true; + } }, p: function update(ctx, dirty) { - if (dirty & /*text*/ 1 && raw_value !== (raw_value = marked__default['default'](marking(/*text*/ ctx[0])) + "")) html_tag.p(raw_value); + if (dirty & /*picked*/ 8) { + set_input_value(input, /*picked*/ ctx[3]); + } + + if (dirty & /*awards*/ 2) { + toggle_class(input, "disabled", /*award*/ ctx[8].owned < 1); + } + + if (dirty & /*awards*/ 2 && i_class_value !== (i_class_value = "" + (/*award*/ ctx[8].icon + " " + /*award*/ ctx[8].color + " svelte-13ovg7j"))) { + attr_dev(i, "class", i_class_value); + } + + if (dirty & /*awards*/ 2 && t2_value !== (t2_value = /*award*/ ctx[8].title + "")) set_data_dev(t2, t2_value); + if (dirty & /*awards*/ 2 && t4_value !== (t4_value = /*award*/ ctx[8].owned + "")) set_data_dev(t4, t4_value); + + if (dirty & /*awards*/ 2) { + toggle_class(label, "disabled", /*award*/ ctx[8].owned < 1); + } }, d: function destroy(detaching) { - if (detaching) detach_dev(html_anchor); - if (detaching) html_tag.d(); + if (detaching) detach_dev(input); + if (detaching) detach_dev(t0); + if (detaching) detach_dev(label); + mounted = false; + dispose(); + } + }; + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_if_block_3.name, + type: "if", + source: "(59:8) {#if award.owned < 1}", + ctx + }); + + return block; + } + + // (58:7) {#each awards as award, index} + function create_each_block(ctx) { + let if_block_anchor; + let if_block = /*award*/ ctx[8].owned < 1 && create_if_block_3(ctx); + + const block = { + c: function create() { + if (if_block) if_block.c(); + if_block_anchor = empty(); + }, + m: function mount(target, anchor) { + if (if_block) if_block.m(target, anchor); + insert_dev(target, if_block_anchor, anchor); + }, + p: function update(ctx, dirty) { + if (/*award*/ ctx[8].owned < 1) { + if (if_block) { + if_block.p(ctx, dirty); + } else { + if_block = create_if_block_3(ctx); + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + if_block.d(1); + if_block = null; + } + }, + d: function destroy(detaching) { + if (if_block) if_block.d(detaching); + if (detaching) detach_dev(if_block_anchor); + } + }; + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_each_block.name, + type: "each", + source: "(58:7) {#each awards as award, index}", + ctx + }); + + return block; + } + + // (70:6) {#if picked != null} + function create_if_block_2(ctx) { + let div2; + let div1; + let i; + let t0; + let div0; + let strong; + let br; + let t3; + let span; + let t5; + let label; + let t7; + let textarea; + let mounted; + let dispose; + + const block = { + c: function create() { + div2 = element("div"); + div1 = element("div"); + i = element("i"); + t0 = space(); + div0 = element("div"); + strong = element("strong"); + strong.textContent = `${/*pickedAward*/ ctx[5].title} Award`; + br = element("br"); + t3 = space(); + span = element("span"); + span.textContent = `${/*pickedAward*/ ctx[5].description}`; + t5 = space(); + label = element("label"); + label.textContent = "Note (optional):"; + t7 = space(); + textarea = element("textarea"); + set_style(i, "font-size", "35px"); + attr_dev(i, "class", "" + (/*pickedAward*/ ctx[5].icon + " " + /*pickedAward*/ ctx[5].color + " svelte-13ovg7j")); + add_location(i, file, 72, 9, 1944); + add_location(strong, file, 74, 10, 2078); + add_location(br, file, 74, 52, 2120); + attr_dev(span, "class", "text-muted"); + add_location(span, file, 75, 10, 2138); + set_style(div0, "margin-left", "15px"); + add_location(div0, file, 73, 9, 2034); + attr_dev(div1, "class", "award-desc p-3 svelte-13ovg7j"); + add_location(div1, file, 71, 8, 1905); + attr_dev(label, "for", "note"); + attr_dev(label, "class", "pt-4"); + add_location(label, file, 78, 8, 2238); + attr_dev(textarea, "id", "note"); + attr_dev(textarea, "name", "note"); + attr_dev(textarea, "class", "form-control"); + attr_dev(textarea, "placeholder", "Note to include in award notification"); + add_location(textarea, file, 79, 8, 2303); + add_location(div2, file, 70, 7, 1890); + }, + m: function mount(target, anchor) { + insert_dev(target, div2, anchor); + append_dev(div2, div1); + append_dev(div1, i); + append_dev(div1, t0); + append_dev(div1, div0); + append_dev(div0, strong); + append_dev(div0, br); + append_dev(div0, t3); + append_dev(div0, span); + append_dev(div2, t5); + append_dev(div2, label); + append_dev(div2, t7); + append_dev(div2, textarea); + set_input_value(textarea, /*note*/ ctx[2]); + + if (!mounted) { + dispose = listen_dev(textarea, "input", /*textarea_input_handler*/ ctx[7]); + mounted = true; + } + }, + p: function update(ctx, dirty) { + if (dirty & /*note*/ 4) { + set_input_value(textarea, /*note*/ ctx[2]); + } + }, + d: function destroy(detaching) { + if (detaching) detach_dev(div2); + mounted = false; + dispose(); + } + }; + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_if_block_2.name, + type: "if", + source: "(70:6) {#if picked != null}", + ctx + }); + + return block; + } + + // (93:3) {:else} + function create_else_block(ctx) { + let button; + let mounted; + let dispose; + + const block = { + c: function create() { + button = element("button"); + button.textContent = "Give Award"; + attr_dev(button, "type", "submit"); + attr_dev(button, "class", "btn btn-link"); + attr_dev(button, "id", "awardButton"); + toggle_class(button, "disabled", /*pickedAward*/ ctx[5] === null); + add_location(button, file, 93, 4, 2849); + }, + m: function mount(target, anchor) { + insert_dev(target, button, anchor); + + if (!mounted) { + dispose = listen_dev(button, "click", submit, false, false, false); + mounted = true; + } + }, + p: noop, + d: function destroy(detaching) { + if (detaching) detach_dev(button); + mounted = false; + dispose(); + } + }; + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_else_block.name, + type: "else", + source: "(93:3) {:else}", + ctx + }); + + return block; + } + + // (88:3) {#if pending} + function create_if_block(ctx) { + let button; + let span; + let t; + + const block = { + c: function create() { + button = element("button"); + span = element("span"); + t = text("\r\n\t\t\t\t\tGifting..."); + attr_dev(span, "class", "spinner-border spinner-border-sm"); + attr_dev(span, "role", "status"); + attr_dev(span, "aria-hidden", "true"); + add_location(span, file, 89, 5, 2712); + attr_dev(button, "class", "btn btn-warning"); + attr_dev(button, "type", "button"); + button.disabled = true; + add_location(button, file, 88, 4, 2650); + }, + m: function mount(target, anchor) { + insert_dev(target, button, anchor); + append_dev(button, span); + append_dev(button, t); + }, + p: noop, + d: function destroy(detaching) { + if (detaching) detach_dev(button); } }; @@ -452,7 +810,7 @@ block, id: create_if_block.name, type: "if", - source: "(34:0) {#if show_preview}", + source: "(88:3) {#if pending}", ctx }); @@ -460,128 +818,136 @@ } function create_fragment(ctx) { - let textarea; + let div5; + let input; let t0; - let div; - let t1; - let pre; + let div4; + let div3; + let div0; + let h5; let t2; - let t3; + let button0; let span; - let mounted; - let dispose; + let i; + let t3; + let div1; + let t4; + let div2; + let button1; + let t6; + let if_block0 = /*loaded*/ ctx[0] && create_if_block_1(ctx); function select_block_type(ctx, dirty) { - if (/*show_preview*/ ctx[1]) return create_if_block_1; + if (/*pending*/ ctx[4]) return create_if_block; return create_else_block; } let current_block_type = select_block_type(ctx); - let if_block0 = current_block_type(ctx); - let if_block1 = /*show_preview*/ ctx[1] && create_if_block(ctx); + let if_block1 = current_block_type(ctx); const block = { c: function create() { - textarea = element("textarea"); + div5 = element("div"); + input = element("input"); t0 = space(); - div = element("div"); - if_block0.c(); - t1 = space(); - pre = element("pre"); + div4 = element("div"); + div3 = element("div"); + div0 = element("div"); + h5 = element("h5"); + h5.textContent = "Give Award"; t2 = space(); - if (if_block1) if_block1.c(); - t3 = space(); + button0 = element("button"); span = element("span"); - attr_dev(textarea, "form", "submitform"); - attr_dev(textarea, "id", "post-text"); - attr_dev(textarea, "class", "form-control rounded"); - attr_dev(textarea, "aria-label", "With textarea"); - attr_dev(textarea, "placeholder", "Optional if you have a link or an image."); - attr_dev(textarea, "rows", "3"); - attr_dev(textarea, "name", "body"); - attr_dev(textarea, "oninput", "charLimit('post-text','character-count-submit-text-form');checkForRequired()"); - attr_dev(textarea, "maxlength", "10000"); - textarea.required = true; - add_location(textarea, file, 21, 0, 468); - attr_dev(div, "class", "btn btn-secondary"); - set_style(div, "float", "right"); - add_location(div, file, 23, 0, 788); - add_location(pre, file, 31, 0, 943); - attr_dev(span, "class", "position-absolute text-small font-weight-bold"); - attr_dev(span, "id", "character-count-submit-text-form"); - set_style(span, "right", "1rem"); - set_style(span, "bottom", "0.5rem"); - set_style(span, "z-index", "3"); - add_location(span, file, 37, 0, 1013); + i = element("i"); + t3 = space(); + div1 = element("div"); + if (if_block0) if_block0.c(); + t4 = space(); + div2 = element("div"); + button1 = element("button"); + button1.textContent = "Cancel"; + t6 = space(); + if_block1.c(); + attr_dev(input, "type", "hidden"); + attr_dev(input, "id", "awardTarget"); + input.value = ""; + add_location(input, file, 44, 0, 744); + attr_dev(h5, "class", "modal-title"); + add_location(h5, file, 48, 4, 952); + attr_dev(i, "class", "far fa-times"); + add_location(i, file, 50, 30, 1105); + attr_dev(span, "aria-hidden", "true"); + add_location(span, file, 50, 5, 1080); + attr_dev(button0, "type", "button"); + attr_dev(button0, "class", "close"); + attr_dev(button0, "data-dismiss", "modal"); + attr_dev(button0, "aria-label", "Close"); + add_location(button0, file, 49, 4, 997); + attr_dev(div0, "class", "modal-header"); + add_location(div0, file, 47, 3, 920); + attr_dev(div1, "id", "awardModalBody"); + attr_dev(div1, "class", "modal-body"); + add_location(div1, file, 53, 3, 1171); + attr_dev(button1, "type", "button"); + attr_dev(button1, "class", "btn btn-link text-muted"); + attr_dev(button1, "data-dismiss", "modal"); + add_location(button1, file, 86, 3, 2536); + attr_dev(div2, "class", "modal-footer"); + add_location(div2, file, 85, 2, 2505); + attr_dev(div3, "class", "modal-content"); + add_location(div3, file, 46, 2, 888); + attr_dev(div4, "class", "modal-dialog modal-dialog-scrollable modal-dialog-centered"); + attr_dev(div4, "role", "document"); + add_location(div4, file, 45, 1, 796); + attr_dev(div5, "id", "svelte-app2"); + add_location(div5, file, 43, 0, 720); }, l: function claim(nodes) { throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); }, m: function mount(target, anchor) { - insert_dev(target, textarea, anchor); - set_input_value(textarea, /*text*/ ctx[0]); - insert_dev(target, t0, anchor); - insert_dev(target, div, anchor); - if_block0.m(div, null); - insert_dev(target, t1, anchor); - insert_dev(target, pre, anchor); - insert_dev(target, t2, anchor); - if (if_block1) if_block1.m(target, anchor); - insert_dev(target, t3, anchor); - insert_dev(target, span, anchor); - - if (!mounted) { - dispose = [ - listen_dev(textarea, "input", /*textarea_input_handler*/ ctx[3]), - listen_dev(div, "click", /*togglePreview*/ ctx[2], false, false, false) - ]; - - mounted = true; - } + insert_dev(target, div5, anchor); + append_dev(div5, input); + append_dev(div5, t0); + append_dev(div5, div4); + append_dev(div4, div3); + append_dev(div3, div0); + append_dev(div0, h5); + append_dev(div0, t2); + append_dev(div0, button0); + append_dev(button0, span); + append_dev(span, i); + append_dev(div3, t3); + append_dev(div3, div1); + if (if_block0) if_block0.m(div1, null); + append_dev(div3, t4); + append_dev(div3, div2); + append_dev(div2, button1); + append_dev(div2, t6); + if_block1.m(div2, null); }, p: function update(ctx, [dirty]) { - if (dirty & /*text*/ 1) { - set_input_value(textarea, /*text*/ ctx[0]); - } - - if (current_block_type !== (current_block_type = select_block_type(ctx))) { - if_block0.d(1); - if_block0 = current_block_type(ctx); - + if (/*loaded*/ ctx[0]) { if (if_block0) { + if_block0.p(ctx, dirty); + } else { + if_block0 = create_if_block_1(ctx); if_block0.c(); - if_block0.m(div, null); + if_block0.m(div1, null); } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; } - if (/*show_preview*/ ctx[1]) { - if (if_block1) { - if_block1.p(ctx, dirty); - } else { - if_block1 = create_if_block(ctx); - if_block1.c(); - if_block1.m(t3.parentNode, t3); - } - } else if (if_block1) { - if_block1.d(1); - if_block1 = null; - } + if_block1.p(ctx, dirty); }, i: noop, o: noop, d: function destroy(detaching) { - if (detaching) detach_dev(textarea); - if (detaching) detach_dev(t0); - if (detaching) detach_dev(div); - if_block0.d(); - if (detaching) detach_dev(t1); - if (detaching) detach_dev(pre); - if (detaching) detach_dev(t2); - if (if_block1) if_block1.d(detaching); - if (detaching) detach_dev(t3); - if (detaching) detach_dev(span); - mounted = false; - run_all(dispose); + if (detaching) detach_dev(div5); + if (if_block0) if_block0.d(); + if_block1.d(); } }; @@ -596,26 +962,38 @@ return block; } - function marking(markdown) { - let emojis = Array.from(markdown.matchAll(/:(.{1,30}?):/gi)); - - if (emojis != null) { - for (let i = 0; i < emojis.length; i++) { - markdown = markdown.replace(emojis[i][0], ""); - } - } - - return markdown; + function submit() { + this.pending = true; + const target = document.getElementById("awardTarget").value; + const f = new FormData(); + f.append("formkey", formkey()); + f.append("kind", this.pickedAward.kind || ""); + f.append("note", this.note); + fetch(target, { method: "POST", body: f }); + location.reload(); } function instance($$self, $$props, $$invalidate) { let { $$slots: slots = {}, $$scope } = $$props; validate_slots('App', slots, []); - let text = ``; - let show_preview = false; + let loaded = false; + let awards = []; + let pending = false; + let note = ""; + let picked = null; - function togglePreview() { - $$invalidate(1, show_preview = !show_preview); + fetch('/awards').then(response => response.json()).then(json => { + $$invalidate(1, awards = json); + }); + + loaded = true; + + function pickedAward() { + if (picked !== null) { + return awards[picked]; + } else { + return null; + } } const writable_props = []; @@ -624,29 +1002,48 @@ if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console.warn(` was created with unknown prop '${key}'`); }); + function input_change_handler() { + picked = this.value; + $$invalidate(3, picked); + } + function textarea_input_handler() { - text = this.value; - $$invalidate(0, text); + note = this.value; + $$invalidate(2, note); } $$self.$capture_state = () => ({ - marked: marked__default['default'], - text, - show_preview, - marking, - togglePreview + loaded, + awards, + pending, + note, + picked, + pickedAward, + submit }); $$self.$inject_state = $$props => { - if ('text' in $$props) $$invalidate(0, text = $$props.text); - if ('show_preview' in $$props) $$invalidate(1, show_preview = $$props.show_preview); + if ('loaded' in $$props) $$invalidate(0, loaded = $$props.loaded); + if ('awards' in $$props) $$invalidate(1, awards = $$props.awards); + if ('pending' in $$props) $$invalidate(4, pending = $$props.pending); + if ('note' in $$props) $$invalidate(2, note = $$props.note); + if ('picked' in $$props) $$invalidate(3, picked = $$props.picked); }; if ($$props && "$$inject" in $$props) { $$self.$inject_state($$props.$$inject); } - return [text, show_preview, togglePreview, textarea_input_handler]; + return [ + loaded, + awards, + note, + picked, + pending, + pickedAward, + input_change_handler, + textarea_input_handler + ]; } class App extends SvelteComponentDev { @@ -664,8 +1061,8 @@ } new App({ - target: document.querySelector('#svelte-app') + target: document.querySelector('#svelte-app2') }); -}(marked)); +}()); //# sourceMappingURL=bundle.js.map diff --git a/files/assets/js/bundle2.js b/files/assets/js/bundle2.js index 562f378ca..c5e7d31b6 100644 --- a/files/assets/js/bundle2.js +++ b/files/assets/js/bundle2.js @@ -31,21 +31,12 @@ function is_empty(obj) { return Object.keys(obj).length === 0; } - function append(target, node) { - target.appendChild(node); - } function insert(target, node, anchor) { target.insertBefore(node, anchor || null); } function detach(node) { node.parentNode.removeChild(node); } - function destroy_each(iterations, detaching) { - for (let i = 0; i < iterations.length; i += 1) { - if (iterations[i]) - iterations[i].d(detaching); - } - } function element(name) { return document.createElement(name); } @@ -77,14 +68,44 @@ function set_style(node, key, value, important) { node.style.setProperty(key, value, important ? 'important' : ''); } - function toggle_class(element, name, toggle) { - element.classList[toggle ? 'add' : 'remove'](name); - } function custom_event(type, detail, bubbles = false) { const e = document.createEvent('CustomEvent'); e.initCustomEvent(type, bubbles, false, detail); return e; } + class HtmlTag { + constructor() { + this.e = this.n = null; + } + c(html) { + this.h(html); + } + m(html, target, anchor = null) { + if (!this.e) { + this.e = element(target.nodeName); + this.t = target; + this.c(html); + } + this.i(anchor); + } + h(html) { + this.e.innerHTML = html; + this.n = Array.from(this.e.childNodes); + } + i(anchor) { + for (let i = 0; i < this.n.length; i += 1) { + insert(this.t, this.n[i], anchor); + } + } + p(html) { + this.d(); + this.h(html); + this.i(this.a); + } + d() { + this.n.forEach(detach); + } + } let current_component; function set_current_component(component) { @@ -290,10 +311,6 @@ function dispatch_dev(type, detail) { document.dispatchEvent(custom_event(type, Object.assign({ version: '3.42.6' }, detail), true)); } - function append_dev(target, node) { - dispatch_dev('SvelteDOMInsert', { target, node }); - append(target, node); - } function insert_dev(target, node, anchor) { dispatch_dev('SvelteDOMInsert', { target, node, anchor }); insert(target, node, anchor); @@ -322,22 +339,6 @@ else dispatch_dev('SvelteDOMSetAttribute', { node, attribute, value }); } - function set_data_dev(text, data) { - data = '' + data; - if (text.wholeText === data) - return; - dispatch_dev('SvelteDOMSetData', { node: text, data }); - text.data = data; - } - function validate_each_argument(arg) { - if (typeof arg !== 'string' && !(arg && typeof arg === 'object' && 'length' in arg)) { - let msg = '{#each} only iterates over array-like objects.'; - if (typeof Symbol === 'function' && arg && Symbol.iterator in arg) { - msg += ' You can use a spread to convert this iterable into an array.'; - } - throw new Error(msg); - } - } function validate_slots(name, slot, keys) { for (const slot_key of Object.keys(slot)) { if (!~keys.indexOf(slot_key)) { @@ -368,402 +369,19 @@ /* src\App.svelte generated by Svelte v3.42.6 */ const file = "src\\App.svelte"; - function get_each_context(ctx, list, i) { - const child_ctx = ctx.slice(); - child_ctx[10] = list[i]; - child_ctx[12] = i; - return child_ctx; - } - - // (58:4) {#if loaded} - function create_if_block_1(ctx) { - let form; - let div; - let t; - let each_value = /*awards*/ ctx[1]; - validate_each_argument(each_value); - let each_blocks = []; - - for (let i = 0; i < each_value.length; i += 1) { - each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i)); - } - - let if_block = /*picked*/ ctx[3] != null && create_if_block_2(ctx); - - const block = { - c: function create() { - form = element("form"); - div = element("div"); - - for (let i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].c(); - } - - t = space(); - if (if_block) if_block.c(); - attr_dev(div, "class", "card-columns awards-wrapper svelte-13ovg7j"); - add_location(div, file, 59, 6, 1363); - attr_dev(form, "class", "pt-3 pb-0"); - add_location(form, file, 58, 5, 1331); - }, - m: function mount(target, anchor) { - insert_dev(target, form, anchor); - append_dev(form, div); - - for (let i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].m(div, null); - } - - append_dev(form, t); - if (if_block) if_block.m(form, null); - }, - p: function update(ctx, dirty) { - if (dirty & /*awards, picked*/ 10) { - each_value = /*awards*/ ctx[1]; - validate_each_argument(each_value); - let i; - - for (i = 0; i < each_value.length; i += 1) { - const child_ctx = get_each_context(ctx, each_value, i); - - if (each_blocks[i]) { - each_blocks[i].p(child_ctx, dirty); - } else { - each_blocks[i] = create_each_block(child_ctx); - each_blocks[i].c(); - each_blocks[i].m(div, null); - } - } - - for (; i < each_blocks.length; i += 1) { - each_blocks[i].d(1); - } - - each_blocks.length = each_value.length; - } - - if (/*picked*/ ctx[3] != null) { - if (if_block) { - if_block.p(ctx, dirty); - } else { - if_block = create_if_block_2(ctx); - if_block.c(); - if_block.m(form, null); - } - } else if (if_block) { - if_block.d(1); - if_block = null; - } - }, - d: function destroy(detaching) { - if (detaching) detach_dev(form); - destroy_each(each_blocks, detaching); - if (if_block) if_block.d(); - } - }; - - dispatch_dev("SvelteRegisterBlock", { - block, - id: create_if_block_1.name, - type: "if", - source: "(58:4) {#if loaded}", - ctx - }); - - return block; - } - - // (62:8) {#if award.owned < 1} - function create_if_block_3(ctx) { - let input; - let t0; - let label; - let i; - let i_class_value; - let br; - let t1; - let span1; - let t2_value = /*award*/ ctx[10].title + ""; - let t2; - let t3; - let span0; - let t4_value = /*award*/ ctx[10].owned + ""; - let t4; - let t5; - let t6; - let mounted; - let dispose; - - const block = { - c: function create() { - input = element("input"); - t0 = space(); - label = element("label"); - i = element("i"); - br = element("br"); - t1 = space(); - span1 = element("span"); - t2 = text(t2_value); - t3 = text("/span>\r\n\t\t\t\t\t\t\t\t\t\t"); - span0 = element("span"); - t4 = text(t4_value); - t5 = text(" owned"); - t6 = space(); - attr_dev(input, "type", "radio"); - attr_dev(input, "id", /*index*/ ctx[12]); - attr_dev(input, "class", "svelte-13ovg7j"); - toggle_class(input, "disabled", /*award*/ ctx[10].owned < 1); - add_location(input, file, 62, 9, 1485); - attr_dev(i, "class", i_class_value = "" + (/*award*/ ctx[10].icon + " " + /*award*/ ctx[10].color + " svelte-13ovg7j")); - add_location(i, file, 64, 10, 1665); - add_location(br, file, 64, 52, 1707); - attr_dev(span0, "class", "text-muted"); - add_location(span0, file, 66, 10, 1827); - attr_dev(span1, "class", "d-block pt-2"); - set_style(span1, "font-weight", "bold"); - set_style(span1, "font-size", "14px"); - add_location(span1, file, 65, 10, 1725); - attr_dev(label, "class", "card svelte-13ovg7j"); - attr_dev(label, "for", /*index*/ ctx[12]); - toggle_class(label, "disabled", /*award*/ ctx[10].owned < 1); - add_location(label, file, 63, 9, 1584); - }, - m: function mount(target, anchor) { - insert_dev(target, input, anchor); - set_input_value(input, /*picked*/ ctx[3]); - insert_dev(target, t0, anchor); - insert_dev(target, label, anchor); - append_dev(label, i); - append_dev(label, br); - append_dev(label, t1); - append_dev(label, span1); - append_dev(span1, t2); - append_dev(span1, t3); - append_dev(span1, span0); - append_dev(span0, t4); - append_dev(span0, t5); - append_dev(span1, t6); - - if (!mounted) { - dispose = listen_dev(input, "change", /*input_change_handler*/ ctx[6]); - mounted = true; - } - }, - p: function update(ctx, dirty) { - if (dirty & /*picked*/ 8) { - set_input_value(input, /*picked*/ ctx[3]); - } - - if (dirty & /*awards*/ 2) { - toggle_class(input, "disabled", /*award*/ ctx[10].owned < 1); - } - - if (dirty & /*awards*/ 2 && i_class_value !== (i_class_value = "" + (/*award*/ ctx[10].icon + " " + /*award*/ ctx[10].color + " svelte-13ovg7j"))) { - attr_dev(i, "class", i_class_value); - } - - if (dirty & /*awards*/ 2 && t2_value !== (t2_value = /*award*/ ctx[10].title + "")) set_data_dev(t2, t2_value); - if (dirty & /*awards*/ 2 && t4_value !== (t4_value = /*award*/ ctx[10].owned + "")) set_data_dev(t4, t4_value); - - if (dirty & /*awards*/ 2) { - toggle_class(label, "disabled", /*award*/ ctx[10].owned < 1); - } - }, - d: function destroy(detaching) { - if (detaching) detach_dev(input); - if (detaching) detach_dev(t0); - if (detaching) detach_dev(label); - mounted = false; - dispose(); - } - }; - - dispatch_dev("SvelteRegisterBlock", { - block, - id: create_if_block_3.name, - type: "if", - source: "(62:8) {#if award.owned < 1}", - ctx - }); - - return block; - } - - // (61:7) {#each awards as award, index} - function create_each_block(ctx) { - let if_block_anchor; - let if_block = /*award*/ ctx[10].owned < 1 && create_if_block_3(ctx); - - const block = { - c: function create() { - if (if_block) if_block.c(); - if_block_anchor = empty(); - }, - m: function mount(target, anchor) { - if (if_block) if_block.m(target, anchor); - insert_dev(target, if_block_anchor, anchor); - }, - p: function update(ctx, dirty) { - if (/*award*/ ctx[10].owned < 1) { - if (if_block) { - if_block.p(ctx, dirty); - } else { - if_block = create_if_block_3(ctx); - if_block.c(); - if_block.m(if_block_anchor.parentNode, if_block_anchor); - } - } else if (if_block) { - if_block.d(1); - if_block = null; - } - }, - d: function destroy(detaching) { - if (if_block) if_block.d(detaching); - if (detaching) detach_dev(if_block_anchor); - } - }; - - dispatch_dev("SvelteRegisterBlock", { - block, - id: create_each_block.name, - type: "each", - source: "(61:7) {#each awards as award, index}", - ctx - }); - - return block; - } - - // (73:6) {#if picked != null} - function create_if_block_2(ctx) { - let div2; - let div1; - let i; - let t0; - let div0; - let strong; - let br; - let t3; - let span; - let t5; - let label; - let t7; - let textarea; - let mounted; - let dispose; - - const block = { - c: function create() { - div2 = element("div"); - div1 = element("div"); - i = element("i"); - t0 = space(); - div0 = element("div"); - strong = element("strong"); - strong.textContent = `${/*pickedAward*/ ctx[5].title} Award`; - br = element("br"); - t3 = space(); - span = element("span"); - span.textContent = `${/*pickedAward*/ ctx[5].description}`; - t5 = space(); - label = element("label"); - label.textContent = "Note (optional):"; - t7 = space(); - textarea = element("textarea"); - set_style(i, "font-size", "35px"); - attr_dev(i, "class", "" + (/*pickedAward*/ ctx[5].icon + " " + /*pickedAward*/ ctx[5].color + " svelte-13ovg7j")); - add_location(i, file, 75, 9, 2035); - add_location(strong, file, 77, 10, 2169); - add_location(br, file, 77, 52, 2211); - attr_dev(span, "class", "text-muted"); - add_location(span, file, 78, 10, 2229); - set_style(div0, "margin-left", "15px"); - add_location(div0, file, 76, 9, 2125); - attr_dev(div1, "class", "award-desc p-3 svelte-13ovg7j"); - add_location(div1, file, 74, 8, 1996); - attr_dev(label, "for", "note"); - attr_dev(label, "class", "pt-4"); - add_location(label, file, 81, 8, 2329); - attr_dev(textarea, "id", "note"); - attr_dev(textarea, "name", "note"); - attr_dev(textarea, "class", "form-control"); - attr_dev(textarea, "placeholder", "Note to include in award notification"); - add_location(textarea, file, 82, 8, 2394); - add_location(div2, file, 73, 7, 1981); - }, - m: function mount(target, anchor) { - insert_dev(target, div2, anchor); - append_dev(div2, div1); - append_dev(div1, i); - append_dev(div1, t0); - append_dev(div1, div0); - append_dev(div0, strong); - append_dev(div0, br); - append_dev(div0, t3); - append_dev(div0, span); - append_dev(div2, t5); - append_dev(div2, label); - append_dev(div2, t7); - append_dev(div2, textarea); - set_input_value(textarea, /*note*/ ctx[2]); - - if (!mounted) { - dispose = listen_dev(textarea, "input", /*textarea_input_handler*/ ctx[7]); - mounted = true; - } - }, - p: function update(ctx, dirty) { - if (dirty & /*note*/ 4) { - set_input_value(textarea, /*note*/ ctx[2]); - } - }, - d: function destroy(detaching) { - if (detaching) detach_dev(div2); - mounted = false; - dispose(); - } - }; - - dispatch_dev("SvelteRegisterBlock", { - block, - id: create_if_block_2.name, - type: "if", - source: "(73:6) {#if picked != null}", - ctx - }); - - return block; - } - - // (96:3) {:else} + // (27:1) {:else} function create_else_block(ctx) { - let button; - let mounted; - let dispose; + let t; const block = { c: function create() { - button = element("button"); - button.textContent = "Give Award"; - attr_dev(button, "type", "submit"); - attr_dev(button, "class", "btn btn-link"); - attr_dev(button, "id", "awardButton"); - toggle_class(button, "disabled", /*pickedAward*/ ctx[5] === null); - add_location(button, file, 96, 4, 2940); + t = text("Show preview"); }, m: function mount(target, anchor) { - insert_dev(target, button, anchor); - - if (!mounted) { - dispose = listen_dev(button, "click", submit, false, false, false); - mounted = true; - } + insert_dev(target, t, anchor); }, - p: noop, d: function destroy(detaching) { - if (detaching) detach_dev(button); - mounted = false; - dispose(); + if (detaching) detach_dev(t); } }; @@ -771,41 +389,62 @@ block, id: create_else_block.name, type: "else", - source: "(96:3) {:else}", + source: "(27:1) {:else}", ctx }); return block; } - // (91:3) {#if pending} - function create_if_block(ctx) { - let button; - let span; + // (25:1) {#if show_preview} + function create_if_block_1(ctx) { let t; const block = { c: function create() { - button = element("button"); - span = element("span"); - t = text("\r\n\t\t\t\t\tGifting..."); - attr_dev(span, "class", "spinner-border spinner-border-sm"); - attr_dev(span, "role", "status"); - attr_dev(span, "aria-hidden", "true"); - add_location(span, file, 92, 5, 2803); - attr_dev(button, "class", "btn btn-warning"); - attr_dev(button, "type", "button"); - button.disabled = true; - add_location(button, file, 91, 4, 2741); + t = text("Hide preview"); }, m: function mount(target, anchor) { - insert_dev(target, button, anchor); - append_dev(button, span); - append_dev(button, t); + insert_dev(target, t, anchor); }, - p: noop, d: function destroy(detaching) { - if (detaching) detach_dev(button); + if (detaching) detach_dev(t); + } + }; + + dispatch_dev("SvelteRegisterBlock", { + block, + id: create_if_block_1.name, + type: "if", + source: "(25:1) {#if show_preview}", + ctx + }); + + return block; + } + + // (34:0) {#if show_preview} + function create_if_block(ctx) { + let html_tag; + let raw_value = marked__default['default'](marking(/*text*/ ctx[0])) + ""; + let html_anchor; + + const block = { + c: function create() { + html_tag = new HtmlTag(); + html_anchor = empty(); + html_tag.a = html_anchor; + }, + m: function mount(target, anchor) { + html_tag.m(raw_value, target, anchor); + insert_dev(target, html_anchor, anchor); + }, + p: function update(ctx, dirty) { + if (dirty & /*text*/ 1 && raw_value !== (raw_value = marked__default['default'](marking(/*text*/ ctx[0])) + "")) html_tag.p(raw_value); + }, + d: function destroy(detaching) { + if (detaching) detach_dev(html_anchor); + if (detaching) html_tag.d(); } }; @@ -813,7 +452,7 @@ block, id: create_if_block.name, type: "if", - source: "(91:3) {#if pending}", + source: "(34:0) {#if show_preview}", ctx }); @@ -821,136 +460,128 @@ } function create_fragment(ctx) { - let div5; - let input; + let textarea; let t0; - let div4; - let div3; - let div0; - let h5; + let div; + let t1; + let pre; let t2; - let button0; - let span; - let i; let t3; - let div1; - let t4; - let div2; - let button1; - let t6; - let if_block0 = /*loaded*/ ctx[0] && create_if_block_1(ctx); + let span; + let mounted; + let dispose; function select_block_type(ctx, dirty) { - if (/*pending*/ ctx[4]) return create_if_block; + if (/*show_preview*/ ctx[1]) return create_if_block_1; return create_else_block; } let current_block_type = select_block_type(ctx); - let if_block1 = current_block_type(ctx); + let if_block0 = current_block_type(ctx); + let if_block1 = /*show_preview*/ ctx[1] && create_if_block(ctx); const block = { c: function create() { - div5 = element("div"); - input = element("input"); + textarea = element("textarea"); t0 = space(); - div4 = element("div"); - div3 = element("div"); - div0 = element("div"); - h5 = element("h5"); - h5.textContent = "Give Award"; + div = element("div"); + if_block0.c(); + t1 = space(); + pre = element("pre"); t2 = space(); - button0 = element("button"); - span = element("span"); - i = element("i"); + if (if_block1) if_block1.c(); t3 = space(); - div1 = element("div"); - if (if_block0) if_block0.c(); - t4 = space(); - div2 = element("div"); - button1 = element("button"); - button1.textContent = "Cancel"; - t6 = space(); - if_block1.c(); - attr_dev(input, "type", "hidden"); - attr_dev(input, "id", "awardTarget"); - input.value = ""; - add_location(input, file, 47, 0, 835); - attr_dev(h5, "class", "modal-title"); - add_location(h5, file, 51, 4, 1043); - attr_dev(i, "class", "far fa-times"); - add_location(i, file, 53, 30, 1196); - attr_dev(span, "aria-hidden", "true"); - add_location(span, file, 53, 5, 1171); - attr_dev(button0, "type", "button"); - attr_dev(button0, "class", "close"); - attr_dev(button0, "data-dismiss", "modal"); - attr_dev(button0, "aria-label", "Close"); - add_location(button0, file, 52, 4, 1088); - attr_dev(div0, "class", "modal-header"); - add_location(div0, file, 50, 3, 1011); - attr_dev(div1, "id", "awardModalBody"); - attr_dev(div1, "class", "modal-body"); - add_location(div1, file, 56, 3, 1262); - attr_dev(button1, "type", "button"); - attr_dev(button1, "class", "btn btn-link text-muted"); - attr_dev(button1, "data-dismiss", "modal"); - add_location(button1, file, 89, 3, 2627); - attr_dev(div2, "class", "modal-footer"); - add_location(div2, file, 88, 2, 2596); - attr_dev(div3, "class", "modal-content"); - add_location(div3, file, 49, 2, 979); - attr_dev(div4, "class", "modal-dialog modal-dialog-scrollable modal-dialog-centered"); - attr_dev(div4, "role", "document"); - add_location(div4, file, 48, 1, 887); - attr_dev(div5, "id", "svelte-app2"); - add_location(div5, file, 46, 0, 811); + span = element("span"); + attr_dev(textarea, "form", "submitform"); + attr_dev(textarea, "id", "post-text"); + attr_dev(textarea, "class", "form-control rounded"); + attr_dev(textarea, "aria-label", "With textarea"); + attr_dev(textarea, "placeholder", "Optional if you have a link or an image."); + attr_dev(textarea, "rows", "3"); + attr_dev(textarea, "name", "body"); + attr_dev(textarea, "oninput", "charLimit('post-text','character-count-submit-text-form');checkForRequired()"); + attr_dev(textarea, "maxlength", "10000"); + textarea.required = true; + add_location(textarea, file, 21, 0, 468); + attr_dev(div, "class", "btn btn-secondary"); + set_style(div, "float", "right"); + add_location(div, file, 23, 0, 788); + add_location(pre, file, 31, 0, 943); + attr_dev(span, "class", "position-absolute text-small font-weight-bold"); + attr_dev(span, "id", "character-count-submit-text-form"); + set_style(span, "right", "1rem"); + set_style(span, "bottom", "0.5rem"); + set_style(span, "z-index", "3"); + add_location(span, file, 37, 0, 1013); }, l: function claim(nodes) { throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); }, m: function mount(target, anchor) { - insert_dev(target, div5, anchor); - append_dev(div5, input); - append_dev(div5, t0); - append_dev(div5, div4); - append_dev(div4, div3); - append_dev(div3, div0); - append_dev(div0, h5); - append_dev(div0, t2); - append_dev(div0, button0); - append_dev(button0, span); - append_dev(span, i); - append_dev(div3, t3); - append_dev(div3, div1); - if (if_block0) if_block0.m(div1, null); - append_dev(div3, t4); - append_dev(div3, div2); - append_dev(div2, button1); - append_dev(div2, t6); - if_block1.m(div2, null); + insert_dev(target, textarea, anchor); + set_input_value(textarea, /*text*/ ctx[0]); + insert_dev(target, t0, anchor); + insert_dev(target, div, anchor); + if_block0.m(div, null); + insert_dev(target, t1, anchor); + insert_dev(target, pre, anchor); + insert_dev(target, t2, anchor); + if (if_block1) if_block1.m(target, anchor); + insert_dev(target, t3, anchor); + insert_dev(target, span, anchor); + + if (!mounted) { + dispose = [ + listen_dev(textarea, "input", /*textarea_input_handler*/ ctx[3]), + listen_dev(div, "click", /*togglePreview*/ ctx[2], false, false, false) + ]; + + mounted = true; + } }, p: function update(ctx, [dirty]) { - if (/*loaded*/ ctx[0]) { - if (if_block0) { - if_block0.p(ctx, dirty); - } else { - if_block0 = create_if_block_1(ctx); - if_block0.c(); - if_block0.m(div1, null); - } - } else if (if_block0) { - if_block0.d(1); - if_block0 = null; + if (dirty & /*text*/ 1) { + set_input_value(textarea, /*text*/ ctx[0]); } - if_block1.p(ctx, dirty); + if (current_block_type !== (current_block_type = select_block_type(ctx))) { + if_block0.d(1); + if_block0 = current_block_type(ctx); + + if (if_block0) { + if_block0.c(); + if_block0.m(div, null); + } + } + + if (/*show_preview*/ ctx[1]) { + if (if_block1) { + if_block1.p(ctx, dirty); + } else { + if_block1 = create_if_block(ctx); + if_block1.c(); + if_block1.m(t3.parentNode, t3); + } + } else if (if_block1) { + if_block1.d(1); + if_block1 = null; + } }, i: noop, o: noop, d: function destroy(detaching) { - if (detaching) detach_dev(div5); - if (if_block0) if_block0.d(); - if_block1.d(); + if (detaching) detach_dev(textarea); + if (detaching) detach_dev(t0); + if (detaching) detach_dev(div); + if_block0.d(); + if (detaching) detach_dev(t1); + if (detaching) detach_dev(pre); + if (detaching) detach_dev(t2); + if (if_block1) if_block1.d(detaching); + if (detaching) detach_dev(t3); + if (detaching) detach_dev(span); + mounted = false; + run_all(dispose); } }; @@ -965,15 +596,16 @@ return block; } - function submit() { - this.pending = true; - const target = document.getElementById("awardTarget").value; - const f = new FormData(); - f.append("formkey", formkey()); - f.append("kind", this.pickedAward.kind || ""); - f.append("note", this.note); - fetch(target, { method: "POST", body: f }); - location.reload(); + function marking(markdown) { + let emojis = Array.from(markdown.matchAll(/:(.{1,30}?):/gi)); + + if (emojis != null) { + for (let i = 0; i < emojis.length; i++) { + markdown = markdown.replace(emojis[i][0], ""); + } + } + + return markdown; } function instance($$self, $$props, $$invalidate) { @@ -981,24 +613,9 @@ validate_slots('App', slots, []); let text = ``; let show_preview = false; - let loaded = false; - let awards = []; - let pending = false; - let note = ""; - let picked = null; - fetch('/awards').then(response => response.json()).then(json => { - $$invalidate(1, awards = json); - }); - - loaded = true; - - function pickedAward() { - if (picked !== null) { - return awards[picked]; - } else { - return null; - } + function togglePreview() { + $$invalidate(1, show_preview = !show_preview); } const writable_props = []; @@ -1007,53 +624,29 @@ if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console.warn(` was created with unknown prop '${key}'`); }); - function input_change_handler() { - picked = this.value; - $$invalidate(3, picked); - } - function textarea_input_handler() { - note = this.value; - $$invalidate(2, note); + text = this.value; + $$invalidate(0, text); } $$self.$capture_state = () => ({ marked: marked__default['default'], text, show_preview, - loaded, - awards, - pending, - note, - picked, - pickedAward, - submit + marking, + togglePreview }); $$self.$inject_state = $$props => { - if ('text' in $$props) text = $$props.text; - if ('show_preview' in $$props) show_preview = $$props.show_preview; - if ('loaded' in $$props) $$invalidate(0, loaded = $$props.loaded); - if ('awards' in $$props) $$invalidate(1, awards = $$props.awards); - if ('pending' in $$props) $$invalidate(4, pending = $$props.pending); - if ('note' in $$props) $$invalidate(2, note = $$props.note); - if ('picked' in $$props) $$invalidate(3, picked = $$props.picked); + if ('text' in $$props) $$invalidate(0, text = $$props.text); + if ('show_preview' in $$props) $$invalidate(1, show_preview = $$props.show_preview); }; if ($$props && "$$inject" in $$props) { $$self.$inject_state($$props.$$inject); } - return [ - loaded, - awards, - note, - picked, - pending, - pickedAward, - input_change_handler, - textarea_input_handler - ]; + return [text, show_preview, togglePreview, textarea_input_handler]; } class App extends SvelteComponentDev { @@ -1071,7 +664,7 @@ } new App({ - target: document.querySelector('#svelte-app2') + target: document.querySelector('#svelte-app') }); }(marked)); diff --git a/files/templates/submit.html b/files/templates/submit.html index a81f555a0..772cad0ad 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -7,7 +7,7 @@ - + + + + + +NIGGER NIGGER NIGGER \ No newline at end of file diff --git a/files/templates/comments.html b/files/templates/comments.html index 6a04f25f5..b0f0053c7 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -271,8 +271,7 @@
  • Save
  • {% if v.id!=c.author_id %} -
  • Give Award
  • +
  • Give Award
  • {% endif %}
  • Reply
  • From 4c3460b7f982954b84a1ec0ac52a7d1c5970e5e4 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 13:25:14 +0200 Subject: [PATCH 37/64] fd --- files/assets/js/bundle.js | 2 +- files/templates/award_modal.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/files/assets/js/bundle.js b/files/assets/js/bundle.js index 75976f718..64e363262 100644 --- a/files/assets/js/bundle.js +++ b/files/assets/js/bundle.js @@ -1061,7 +1061,7 @@ } new App({ - target: document.querySelector('#svelte-app2') + target: document.querySelector('#awardModal') }); }()); diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index d69b4fe45..5f5a17a8d 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -1,7 +1,7 @@ - +{% if v %} + {% include "gif_modal.html" %} + {% include "emoji_modal.html" %} + {% include "award_modal.html" %} + {% include "delete_comment_modal.html" %} +{% endif %} +{% include "expanded_image_modal.html" %} +{% include "flag_comment_modal.html" %} \ No newline at end of file diff --git a/files/templates/default.html b/files/templates/default.html index 8647c9751..82566c6ad 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -1297,7 +1297,7 @@ {% block mobilenavbar %} -{% include "mobile_navigation_bar.html" %} + {% include "mobile_navigation_bar.html" %} {% endblock %} {% block actionsModal %} @@ -1337,17 +1337,6 @@ -{% if v %} -{% include "award_modal.html" %} -{% include "flag_post_modal.html" %} -{% include "flag_comment_modal.html" %} -{% include "gif_modal.html" %} -{% include "delete_comment_modal.html" %} -{% include "delete_post_modal.html" %} -{% endif %} - -{% include "expanded_image_modal.html" %} - diff --git a/files/templates/submission.html b/files/templates/submission.html index 4b6ef7b45..83767f63e 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -669,7 +669,7 @@ {% if p.replies %}
    {% with comments=p.replies %} - {% include "comments.html" %} + {% include "comments.html" %} {% endwith %}
    {% elif not p.replies and p.deleted_utc == 0 %} @@ -692,11 +692,9 @@ {% if v and v.id==p.author_id %} -{% include "delete_post_modal.html" %} + {% include "delete_post_modal.html" %} {% endif %} -{% include "delete_comment_modal.html" %} - {% endblock %} @@ -709,8 +707,8 @@ {% endblock %} {% block GIFpicker %} -{% if v %} -{% include "gif_modal.html" %} -{% include "emoji_modal.html" %} -{% endif %} -{% endblock %} + {% if v %} + {% include "award_modal.html" %} + {% endif %} + {% include "expanded_image_modal.html" %} +{% endblock %} \ No newline at end of file diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 0652025ca..9c09dcb45 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -496,4 +496,9 @@ {% endfor %} -{% include "delete_post_modal.html" %} \ No newline at end of file +{% if v %} + {% include "award_modal.html" %} + {% include "delete_post_modal.html" %} +{% endif %} +{% include "expanded_image_modal.html" %} +{% include "flag_post_modal.html" %} \ No newline at end of file From b7b2b7e8d3b3b4d3bf96c239617f1bada83736f7 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 13:44:09 +0200 Subject: [PATCH 39/64] fdfd --- files/classes/user.py | 73 +++++++++++++++++++++++++------- files/routes/awards.py | 14 ------ files/templates/award_modal.html | 2 +- 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 254d49ea3..024cf9b35 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -23,6 +23,53 @@ defaultcolor = environ.get("DEFAULT_COLOR", "fff").strip() defaulttimefilter = environ.get("DEFAULT_TIME_FILTER", "all").strip() cardview = bool(int(environ.get("CARD_VIEW", 1))) +if site_name == "Drama": + AWARDS = { + "ban": { + "kind": "ban", + "title": "One-Day Ban", + "description": "Bans the author for a day.", + "icon": "fas fa-gavel", + "color": "text-danger", + "price": 5000 + }, + "shit": { + "kind": "shit", + "title": "Shit", + "description": "Makes flies swarm a post.", + "icon": "fas fa-poop", + "color": "text-black-50", + "price": 1000 + }, + "stars": { + "kind": "stars", + "title": "Stars", + "description": "Puts stars on the post.", + "icon": "fas fa-sparkles", + "color": "text-warning", + "price": 1000 + } + } +else: + AWARDS = { + "shit": { + "kind": "shit", + "title": "shit", + "description": "Makes flies swarm a post.", + "icon": "fas fa-poop", + "color": "text-black-50", + "price": 1000 + }, + "stars": { + "kind": "stars", + "title": "Stars", + "description": "Puts stars on the post.", + "icon": "fas fa-sparkles", + "color": "text-warning", + "price": 1000 + } + } + class User(Base, Stndrd, Age_times): __tablename__ = "users" id = Column(Integer, primary_key=True) @@ -288,21 +335,6 @@ class User(Base, Stndrd, Age_times): return f"Unban in {text}" - @property - @lazy - def display_awards(self): - - awards = {} - active_awards = [x for x in self.awards if not x.given] - - for a in active_awards: - if a.kind in awards: - awards[a.kind]['count'] += 1 - else: - awards[a.kind] = a.type - awards[a.kind]['count'] = 1 - - return sorted(list(awards.values()), key=lambda x: x['kind'], reverse=True) @property @lazy @@ -626,3 +658,14 @@ class ViewerRelationship(Base): else: years = int(months / 12) return f"{years}yr ago" + +@property +@lazy +def user_awards(v): + + return_value = list(AWARDS.values()) + + user_awards = v.awards + for val in return_value: val['owned'] = user_awards.filter_by(kind=val['kind'], submission_id=None, comment_id=None).count() + + return jsonify(return_value) diff --git a/files/routes/awards.py b/files/routes/awards.py index 8ec44509c..bc230d0d8 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -183,20 +183,6 @@ ALLOW_MULTIPLE = ( "stars" ) - -@app.get("/awards") -@auth_required -def get_awards(v): - - return_value = list(AWARDS.values()) - - user_awards = v.awards - for val in return_value: - val['owned'] = user_awards.filter_by(kind=val['kind'], submission_id=None, comment_id=None).count() - - return jsonify(return_value) - - @app.post("/post//awards") @auth_required @validate_formkey diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index c2d2ff91d..3f8e6c34c 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -1,6 +1,6 @@ -
    {{awards}}
    +
    {{v.user_awards}}
    + + \ No newline at end of file From c23bf5abd0ea118c6af3395bff8bf31fbd65161a Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 17 Sep 2021 16:02:05 +0200 Subject: [PATCH 63/64] fddf --- files/templates/award_modal.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index 54fdeaccf..eecf2c7f0 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -11,7 +11,7 @@