Skip to content

Commit

Permalink
feat: add time_frame parameter for static methods of Limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
Colerar committed Oct 27, 2023
1 parent b88c536 commit 5943282
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions backend/funix/decorator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,16 @@ def __init__(
self.call_history = {}

@staticmethod
def ip(max_calls: int):
return Limiter(max_calls=max_calls, source=LimitSource.IP)
def ip(max_calls: int, time_frame: int = 60):
return Limiter(
max_calls=max_calls, time_frame=time_frame, source=LimitSource.IP
)

@staticmethod
def session(max_calls: int):
return Limiter(max_calls=max_calls, source=LimitSource.SESSION)
def session(max_calls: int, time_frame: int = 60):
return Limiter(
max_calls=max_calls, time_frame=time_frame, source=LimitSource.SESSION
)

def rate_limit(self) -> Optional[Response]:
call_history = self.call_history
Expand Down

0 comments on commit 5943282

Please sign in to comment.