File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 4
4
5
5
from auth .get_user_info import getUserInfoByToken
6
6
from db .supabase .client import get_client
7
+ from uilts .env import get_env_variable
7
8
8
- RATE_LIMIT_REQUESTS = 100
9
- RATE_LIMIT_DURATION = timedelta (minutes = 1 )
9
+ RATE_LIMIT_ENABLED = get_env_variable ("RATE_LIMIT_ENABLED" )
10
+ RATE_LIMIT_REQUESTS = get_env_variable ("RATE_LIMIT_REQUESTS" ) or 100
11
+ RATE_LIMIT_DURATION = timedelta (minutes = int (get_env_variable ("RATE_LIMIT_DURATION" ) or 1 ))
10
12
11
13
async def verify_rate_limit (petercat : str = Cookie (None )):
14
+ if not RATE_LIMIT_ENABLED :
15
+ return
16
+
12
17
if not petercat :
13
18
raise HTTPException (status_code = 403 , detail = "Must Login" )
14
19
user = await getUserInfoByToken (petercat )
@@ -28,7 +33,7 @@ async def verify_rate_limit(petercat: str = Cookie(None)):
28
33
# If the elapsed time is greater than the rate limit duration, reset the count
29
34
user_usage ['request_count' ] = 1
30
35
else :
31
- if user_usage ['request_count' ] >= RATE_LIMIT_REQUESTS :
36
+ if user_usage ['request_count' ] >= int ( RATE_LIMIT_REQUESTS ) :
32
37
# If the request count exceeds the rate limit, return a JSON response with an error message
33
38
raise HTTPException (
34
39
status_code = 429 ,
You can’t perform that action at this time.
0 commit comments