mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-12 02:57:26 +08:00
[Enhance][Bug fix] Improve setting file & ...
- Fix a small bug that `best30` of API cannot have scores whose songs are not in database - At present the setting file can be a module or a file with some of options - Limiter can have multiple rules together now
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from limits import parse, strategies
|
||||
from limits import parse_many, strategies
|
||||
from limits.storage import storage_from_string
|
||||
|
||||
|
||||
@@ -6,23 +6,26 @@ class ArcLimiter:
|
||||
storage = storage_from_string("memory://")
|
||||
strategy = strategies.FixedWindowRateLimiter(storage)
|
||||
|
||||
def __init__(self, limit: str = None, namespace: str = None):
|
||||
self._limit = None
|
||||
self.limit = limit
|
||||
def __init__(self, limit_str: str = None, namespace: str = None):
|
||||
self._limits = None
|
||||
self.limits = limit_str
|
||||
self.namespace = namespace
|
||||
|
||||
@property
|
||||
def limit(self):
|
||||
return self._limit
|
||||
def limits(self):
|
||||
return self._limits
|
||||
|
||||
@limit.setter
|
||||
def limit(self, value):
|
||||
@limits.setter
|
||||
def limits(self, value: str):
|
||||
if value is None:
|
||||
return
|
||||
self._limit = parse(value)
|
||||
self._limits = parse_many(value)
|
||||
|
||||
def hit(self, key: str, cost: int = 1) -> bool:
|
||||
return self.strategy.hit(self.limit, self.namespace, key, cost=cost)
|
||||
flag = True
|
||||
for limit in self.limits:
|
||||
flag &= self.strategy.hit(limit, self.namespace, key, cost)
|
||||
return flag
|
||||
|
||||
def test(self, key: str) -> bool:
|
||||
return self.strategy.test(self.limit, self.namespace, key)
|
||||
return all(self.strategy.test(limit, self.namespace, key) for limit in self.limits)
|
||||
|
||||
Reference in New Issue
Block a user