v1.0.0后端最终修复版
This commit is contained in:
@@ -11,7 +11,6 @@ from fastapi import Request, HTTPException
|
||||
from slowapi import Limiter, _rate_limit_exceeded_handler
|
||||
from slowapi.util import get_remote_address
|
||||
from slowapi.errors import RateLimitExceeded
|
||||
from slowapi.extension import RateLimitDecorator
|
||||
from ..config import settings
|
||||
|
||||
# 创建限流器
|
||||
@@ -24,11 +23,12 @@ def setup_rate_limit(app):
|
||||
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
|
||||
|
||||
def rate_limit(requests: int = None, period: int = None):
|
||||
"""限流装饰器工厂 - 修复版本"""
|
||||
"""限流装饰器工厂"""
|
||||
if not settings.RATE_LIMIT_ENABLED:
|
||||
return lambda func: func
|
||||
|
||||
req = requests or settings.RATE_LIMIT_REQUESTS
|
||||
per = period or settings.RATE_LIMIT_PERIOD
|
||||
|
||||
# 直接返回 slowapi 的限流装饰器
|
||||
return limiter.limit(f"{req}/{per} seconds")
|
||||
@@ -14,4 +14,5 @@ python-jose[cryptography]==3.3.0
|
||||
passlib[bcrypt]==1.7.4
|
||||
aiosmtplib==2.0.2
|
||||
tencentcloud-sdk-python==3.0.1000
|
||||
pycryptodome==3.20.0
|
||||
pycryptodome==3.20.0
|
||||
httpx==0.25.1
|
||||
Reference in New Issue
Block a user