Skip to content

Commit

Permalink
Merge pull request cc004#147 from cc004/fix2
Browse files Browse the repository at this point in the history
fix: result img error
  • Loading branch information
Lanly109 authored Oct 16, 2024
2 parents bbb36dc + 28d5985 commit c5164a2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions autopcr/http_server/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self, host = '0.0.0.0', port = 2, qq_mod = False):

self.web = Blueprint('web', __name__, static_folder=static_path)

# version check & rate limit
self.api_limit = Blueprint('api_limit', __name__, url_prefix = "/api")
self.api = Blueprint('api', __name__, url_prefix = "/api")

self.app = Blueprint('app', __name__, url_prefix = "/daily")
Expand All @@ -37,6 +39,7 @@ def __init__(self, host = '0.0.0.0', port = 2, qq_mod = False):

self.app.register_blueprint(self.web)
self.app.register_blueprint(self.api)
self.app.register_blueprint(self.api_limit)

self.host = host
self.port = port
Expand Down Expand Up @@ -76,15 +79,15 @@ async def inner(*args, **kwargs):

def configure_routes(self):

@self.api.before_request
@self.api_limit.before_request
async def check_app_version():
version = request.headers.get('X-App-Version', None)
if version != APP_VERSION:
return f"后端期望前端版本为{APP_VERSION},请更新", 400
else:
return None

@self.api.errorhandler(RateLimitExceeded)
@self.api_limit.errorhandler(RateLimitExceeded)
async def handle_rate_limit_exceeded_error(error):
return "您冲得太快了,休息一下吧", 429

Expand Down Expand Up @@ -390,7 +393,7 @@ async def validate(): # TODO think to check login or not
validate_ok_dict[id] = ValidateInfo.from_dict(data)
return "", 200

@self.api.route('/login/qq', methods = ['POST'])
@self.api_limit.route('/login/qq', methods = ['POST'])
@rate_limit(1, timedelta(seconds=1))
@rate_limit(3, timedelta(minutes=1))
async def login_qq():
Expand All @@ -407,7 +410,7 @@ async def login_qq():
else:
return "无效的QQ或密码", 400

@self.api.route('/register', methods = ['POST'])
@self.api_limit.route('/register', methods = ['POST'])
@rate_limit(1, timedelta(minutes=1))
async def register():
data = await request.get_json()
Expand Down

0 comments on commit c5164a2

Please sign in to comment.