mirror of
https://github.com/norohind/FDEV-CAPI-Handler.git
synced 2025-06-06 02:13:30 +03:00
add usages count for every token
This commit is contained in:
parent
bc2e13786f
commit
d50df50ca1
@ -103,6 +103,7 @@ class CAPIAuthorizer:
|
||||
return None
|
||||
|
||||
row['expires_over'] = int(row['expires_on']) - int(time.time())
|
||||
|
||||
return row
|
||||
|
||||
def refresh_by_state(self, state: str, force_refresh=False, failure_tolerance=True) -> dict:
|
||||
|
@ -111,7 +111,12 @@ class Model:
|
||||
self.db.execute(sqlite_requests.refresh_times_increment, {'state': state})
|
||||
|
||||
def get_token_for_user(self, state: str) -> dict:
|
||||
return self.db.execute(sqlite_requests.get_token_for_user, {'state': state}).fetchone()
|
||||
sql_params = {'state': state}
|
||||
token = self.db.execute(sqlite_requests.get_token_for_user, sql_params).fetchone()
|
||||
with self.db:
|
||||
self.db.execute(sqlite_requests.increment_usages, sql_params)
|
||||
|
||||
return token
|
||||
|
||||
def list_all_records(self) -> list:
|
||||
return self.db.execute(sqlite_requests.select_nickname_state_all).fetchall()
|
||||
|
@ -8,7 +8,8 @@ schema = """create table if not exists authorizations (
|
||||
expires_in text,
|
||||
timestamp_got_expires_in text,
|
||||
nickname text unique,
|
||||
refresh_tries int default 0
|
||||
refresh_tries int default 0,
|
||||
usages int default 0
|
||||
);"""
|
||||
|
||||
insert_auth_init = """insert into authorizations
|
||||
@ -48,3 +49,5 @@ from authorizations where state = :state;"""
|
||||
select_nickname_state_all = """select nickname, state from authorizations where nickname is not null;"""
|
||||
|
||||
del_orphans = """delete from authorizations where nickname is null;"""
|
||||
|
||||
increment_usages = "update authorizations set usages = usages + 1 where state = :state;"
|
||||
|
Loading…
x
Reference in New Issue
Block a user