1
0
mirror of https://github.com/LibreTranslate/LibreTranslate.git synced 2024-12-18 08:27:03 +02:00

Merge pull request #96 from pierotofy/limitsfix

Fix daily limits for API key holders
This commit is contained in:
Piero Toffanin 2021-06-03 10:42:02 -04:00 committed by GitHub
commit 9648f4ad33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,13 +27,8 @@ def get_remote_address():
return ip
def get_routes_limits(default_req_limit, daily_req_limit, api_keys_db):
if default_req_limit == -1:
# TODO: better way?
default_req_limit = 9999999999999
def limits():
req_limit = default_req_limit
def get_req_limits(default_limit, api_keys_db, multiplier = 1):
req_limit = default_limit
if api_keys_db:
if request.is_json:
@ -47,12 +42,24 @@ def get_routes_limits(default_req_limit, daily_req_limit, api_keys_db):
if db_req_limit is not None:
req_limit = db_req_limit
return "%s per minute" % req_limit
return req_limit
res = [limits]
def get_routes_limits(default_req_limit, daily_req_limit, api_keys_db):
if default_req_limit == -1:
# TODO: better way?
default_req_limit = 9999999999999
def minute_limits():
return "%s per minute" % get_req_limits(default_req_limit, api_keys_db)
def daily_limits():
return "%s per day" % get_req_limits(daily_req_limit, api_keys_db, 1440)
res = [minute_limits]
if daily_req_limit > 0:
res.append("%s per day" % daily_req_limit)
res.append(daily_limits)
return res