From ea2077991336b3eb9fc8f01cb1b47de2f48ff23a Mon Sep 17 00:00:00 2001 From: hole-thu Date: Fri, 24 Dec 2021 00:17:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=91=E7=AE=A1=E7=90=86=E5=91=98=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E8=A2=AB=E4=B8=BE=E6=8A=A5=20&=20=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E5=85=B3=E6=B3=A8=E8=A7=A3=E9=99=A4=E4=B8=BE=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hole.py | 21 +++++++++++---------- utils.py | 1 + 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/hole.py b/hole.py index ad3c796..7663209 100644 --- a/hole.py +++ b/hole.py @@ -399,15 +399,13 @@ def attention(): if username[:4] == 'tmp_': abort(403) - s = request.form.get('switch') - if s not in ['0', '1']: + s = request.form.get('switch', type=int) + if s not in [0, 1]: abort(422) - pid = get_num(request.form.get('pid')) + pid = request.form.get('pid', type=int) - post = Post.query.get(pid) - if not post: - abort(404) + post = Post.query.get_or_404(pid) at = Attention.query.filter_by( name_hash=hash_name(username), pid=pid @@ -419,16 +417,19 @@ def attention(): if post.hot_score != -1: post.hot_score += 2 - if(at.disabled != (s == '0')): - at.disabled = (s == '0') - post.likenum += 1 - 2 * int(s == '0') + if at.disabled == bool(s): + at.disabled = not bool(s) + post.likenum += 2 * s - 1 + + if is_admin(username) and s: + post.is_reported = False db.session.commit() return { 'code': 0, 'likenum': post.likenum, - 'attention': (s == '1') + 'attention': bool(s) } diff --git a/utils.py b/utils.py index c069d6f..3f34662 100644 --- a/utils.py +++ b/utils.py @@ -82,6 +82,7 @@ def map_post(p, name, mc=50): if rds.sismember(RDS_KEY_DANGEROUS_USERS, p.name_hash): r['dangerous_user'] = p.name_hash[:4] r['blocked_count'] = rds.hget(RDS_KEY_BLOCKED_COUNT, p.name_hash) + r['is_reported'] = p.is_reported return r