feat: 为token支持独立client_id绑定

This commit is contained in:
TheSmallHanCat
2025-12-04 17:33:03 +08:00
parent 0a09cd5b00
commit e3819a4805
5 changed files with 58 additions and 16 deletions

View File

@@ -194,6 +194,7 @@ class Database:
("video_enabled", "BOOLEAN DEFAULT 1"),
("image_concurrency", "INTEGER DEFAULT -1"),
("video_concurrency", "INTEGER DEFAULT -1"),
("client_id", "TEXT"),
]
for col_name, col_type in columns_to_add:
@@ -269,6 +270,7 @@ class Database:
name TEXT NOT NULL,
st TEXT,
rt TEXT,
client_id TEXT,
remark TEXT,
expiry_time TIMESTAMP,
is_active BOOLEAN DEFAULT 1,
@@ -561,12 +563,12 @@ class Database:
"""Add a new token"""
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute("""
INSERT INTO tokens (token, email, username, name, st, rt, remark, expiry_time, is_active,
INSERT INTO tokens (token, email, username, name, st, rt, client_id, remark, expiry_time, is_active,
plan_type, plan_title, subscription_end, sora2_supported, sora2_invite_code,
sora2_redeemed_count, sora2_total_count, sora2_remaining_count, sora2_cooldown_until,
image_enabled, video_enabled, image_concurrency, video_concurrency)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (token.token, token.email, "", token.name, token.st, token.rt,
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (token.token, token.email, "", token.name, token.st, token.rt, token.client_id,
token.remark, token.expiry_time, token.is_active,
token.plan_type, token.plan_title, token.subscription_end,
token.sora2_supported, token.sora2_invite_code,
@@ -701,6 +703,7 @@ class Database:
token: Optional[str] = None,
st: Optional[str] = None,
rt: Optional[str] = None,
client_id: Optional[str] = None,
remark: Optional[str] = None,
expiry_time: Optional[datetime] = None,
plan_type: Optional[str] = None,
@@ -710,7 +713,7 @@ class Database:
video_enabled: Optional[bool] = None,
image_concurrency: Optional[int] = None,
video_concurrency: Optional[int] = None):
"""Update token (AT, ST, RT, remark, expiry_time, subscription info, image_enabled, video_enabled)"""
"""Update token (AT, ST, RT, client_id, remark, expiry_time, subscription info, image_enabled, video_enabled)"""
async with aiosqlite.connect(self.db_path) as db:
# Build dynamic update query
updates = []
@@ -728,6 +731,10 @@ class Database:
updates.append("rt = ?")
params.append(rt)
if client_id is not None:
updates.append("client_id = ?")
params.append(client_id)
if remark is not None:
updates.append("remark = ?")
params.append(remark)