同步更新:重构路由、服务模块,更新前端构建
This commit is contained in:
@@ -201,11 +201,33 @@ def require_ip_not_locked(f):
|
||||
def decorated_function(*args, **kwargs):
|
||||
ip_address = request.remote_addr
|
||||
|
||||
if ip_rate_limiter.is_locked(ip_address):
|
||||
return jsonify({
|
||||
"error": "由于多次失败尝试,您的IP已被临时锁定",
|
||||
"locked_until": ip_rate_limiter._locked.get(ip_address, 0)
|
||||
}), 429
|
||||
# P0 / O-01:统一使用 services.state 的线程安全限流状态
|
||||
try:
|
||||
from services.state import check_ip_rate_limit, safe_get_ip_lock_until
|
||||
|
||||
allowed, error_msg = check_ip_rate_limit(ip_address)
|
||||
if not allowed:
|
||||
return (
|
||||
jsonify(
|
||||
{
|
||||
"error": error_msg or "由于多次失败尝试,您的IP已被临时锁定",
|
||||
"locked_until": safe_get_ip_lock_until(ip_address),
|
||||
}
|
||||
),
|
||||
429,
|
||||
)
|
||||
except Exception:
|
||||
# 兜底:沿用旧实现(避免极端情况下阻断业务)
|
||||
if ip_rate_limiter.is_locked(ip_address):
|
||||
return (
|
||||
jsonify(
|
||||
{
|
||||
"error": "由于多次失败尝试,您的IP已被临时锁定",
|
||||
"locked_until": ip_rate_limiter._locked.get(ip_address, 0),
|
||||
}
|
||||
),
|
||||
429,
|
||||
)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user