From f9429d4d63163e439451decc2ae8de0a31c61d06 Mon Sep 17 00:00:00 2001 From: hole-thu Date: Sun, 19 Dec 2021 22:02:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=88=B6=E4=B8=B4=E6=97=B6=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E7=9A=84=E6=8A=95=E7=A5=A8=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hole.py | 4 +++- utils.py | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/hole.py b/hole.py index 3ed6351..0ddf018 100644 --- a/hole.py +++ b/hole.py @@ -10,7 +10,7 @@ from sqlalchemy.sql.expression import func from mastodon import Mastodon from models import db, User, Post, Comment, Attention, TagRecord, Syslog -from utils import get_current_username, map_post, map_comment, map_syslog, check_attention, hash_name, look, get_num, tmp_token, is_admin, check_can_del, rds, RDS_KEY_POLL_OPTS, RDS_KEY_POLL_VOTES, gen_poll_dict +from utils import get_current_username, map_post, map_comment, map_syslog, check_attention, hash_name, look, get_num, tmp_token, is_admin, check_can_del, rds, RDS_KEY_POLL_OPTS, RDS_KEY_POLL_VOTES, gen_poll_dict, name_with_tmp_limit app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///hole.db' @@ -535,6 +535,8 @@ def edit_hot_score(): @limiter.limit("100 / hour; 1 / 2 second") def add_vote(): username = get_current_username() + username = name_with_tmp_limit(username) + pid = request.form.get('pid', type=int) vote = request.form.get('vote') diff --git a/utils.py b/utils.py index eab6a70..5f84e53 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,8 @@ import hashlib import time import redis +from datetime import date + from flask import request, abort, current_app from models import User, Attention, Syslog from config import RDS_CONFIG, ADMINS, ENABLE_TMP @@ -74,7 +76,7 @@ def map_post(p, name, mc=50): def gen_poll_dict(pid, name): if not rds.exists(RDS_KEY_POLL_OPTS % pid): return None - + name = name_with_tmp_limit(name) vote = None answers = [] for idx, opt in enumerate(rds.lrange(RDS_KEY_POLL_OPTS % pid, 0, -1)): @@ -91,6 +93,11 @@ def gen_poll_dict(pid, name): } +def name_with_tmp_limit(name: str) -> str: + return 'tmp:%s' % date.today() if name.startswith( + 'tmp_') else name + + def map_comment(p, name): names = {p.name_hash: 0}