2026-08-24 01:37:14 +02:00
|
|
|
import sqlite3
|
|
|
|
|
|
2026-08-24 13:35:59 +02:00
|
|
|
def init_db(path: str) -> None:
|
|
|
|
|
with sqlite3.connect(path) as connection:
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
cursor.execute('''
|
|
|
|
|
CREATE TABLE IF NOT EXISTS Tokens (
|
|
|
|
|
TOKEN TEXT PRIMARY KEY NOT NULL,
|
|
|
|
|
USERID INTEGER NOT NULL,
|
|
|
|
|
NAME TEXT NOT NULL
|
|
|
|
|
)
|
|
|
|
|
''')
|
|
|
|
|
|
|
|
|
|
cursor.execute('''
|
|
|
|
|
CREATE TABLE IF NOT EXISTS Domains (
|
|
|
|
|
DOMAIN TEXT PRIMARY KEY NOT NULL,
|
|
|
|
|
USERID INTEGER NOT NULL
|
|
|
|
|
)
|
|
|
|
|
''')
|
|
|
|
|
|
|
|
|
|
connection.commit()
|
|
|
|
|
cursor.close()
|
2026-08-24 01:37:14 +02:00
|
|
|
|
|
|
|
|
def check_token_domain(db_path: str, token: str, domain: str) -> bool:
|
|
|
|
|
with sqlite3.connect(db_path) as connection:
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
cursor.execute('''
|
|
|
|
|
SELECT COUNT(*) FROM Tokens
|
2026-08-24 13:35:59 +02:00
|
|
|
JOIN Domains ON Tokens.userid = Domains.userid
|
2026-08-24 01:37:14 +02:00
|
|
|
WHERE token = ?
|
|
|
|
|
AND domain = ?
|
|
|
|
|
''', (token,domain))
|
|
|
|
|
|
|
|
|
|
return cursor.fetchone()[0] == 1
|