Initial certificate system
This commit is contained in:
12
backend/app/services/rate_limit.py
Normal file
12
backend/app/services/rate_limit.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import time
|
||||
|
||||
_hits: dict[str, list[float]] = {}
|
||||
|
||||
|
||||
def hit_too_often(key: str, limit: int, window_seconds: int) -> bool:
|
||||
now = time.time()
|
||||
start = now - window_seconds
|
||||
recent = [value for value in _hits.get(key, []) if value >= start]
|
||||
recent.append(now)
|
||||
_hits[key] = recent
|
||||
return len(recent) > limit
|
||||
Reference in New Issue
Block a user