Skip to content

Commit

Permalink
fix: 修复请求间隔时间计算错误
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-zhix authored and Folltoshe committed Dec 2, 2023
1 parent 7e3161a commit 01b4a4e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ConfigReadException(Exception):
"global": 0,
"ip": 0,
"desc": "请求速率限制,global为全局,ip为单个ip,填入的值为至少间隔多久才能进行一次请求,单位:秒,不限制请填为0"
}
},
"key": {
"enable": False,
"_enable-desc": "是否开启请求key,开启后只有请求头中包含key,且值一样时可以访问API",
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ def check():
return utils.format_dict_json({"code": 1, "msg": "您的IP已被封禁", "data": None}), 403
# check global rate limit
if (
(config.getRequestTime('global') - time.time())
(time.time() - config.getRequestTime('global'))
<
(config.read_config("security.rate_limit.global"))
):
return utils.format_dict_json({"code": 5, "msg": "全局限速", "data": None}), 429
if (
(config.getRequestTime(request.remote_addr) - time.time())
(time.time() - config.getRequestTime(request.remote_addr))
<
(config.read_config("security.rate_limit.ip"))
):
Expand Down

0 comments on commit 01b4a4e

Please # to comment.