feat(huya): 精英宝典工作台支持导入外部 CK

- 新增 POST /api/huya/workbench-accounts/import-cookies(huya:task + huya:import):
  外部 CK 复用现有解析入库后直接加入当前用户的工作台集合,导入完即可在工作台执行
  「生成开通支付码/绑定二维码/查询角色/刷新积分」等操作
- 新账号自动 assigned_to=导入者:客服的账号列表按归属过滤,不设归属会「导入成功但看不到」
- import_huya_cookies_detailed 返回账号对象供工作台复用,原 import_huya_cookies 行为不变
- 工作台账号卡片新增「导入外部 CK」入口(huya:import 权限控制)与导入弹窗

验证:新增 tests/test_huya_workbench_import_ck.py(入库、归属、工作台集合、重复导入幂等、
全脏数据不建记录);按 AGENTS.md 做了反向验证(关掉归属赋值后该用例变红,还原后恢复)。
前端 tsc -b 与全量 pytest 通过。
This commit is contained in:
yml2213
2026-10-15 14:56:58 +08:00
parent f540dcfc29
commit 4ce30e5c26
10 changed files with 304 additions and 9 deletions
+24 -7
View File
@@ -349,9 +349,16 @@ def upsert_huya_cookie(
return account
def import_huya_cookies(db: Session, text: str, tag: str = "") -> tuple[int, int]:
"""导入虎牙 Cookie,返回 (成功数, 跳过数)。"""
created_or_updated = 0
def import_huya_cookies_detailed(
db: Session, text: str, tag: str = "", assign_to: int | None = None
) -> tuple[list[HuyaAccount], int]:
"""导入虎牙 Cookie,返回 (账号列表, 跳过数)。
与 ``import_huya_cookies`` 的差别:把每个账号对象交回调用方 —— 工作台
「导入外部 CK」需要拿到刚导入的账号加入自己的工作台集合;``assign_to``
用于给尚无归属的新账号打上导入者(否则客服看不到自己导入的账号)。
"""
accounts: list[HuyaAccount] = []
skipped = 0
tag = (tag or "").strip()
@@ -361,12 +368,22 @@ def import_huya_cookies(db: Session, text: str, tag: str = "") -> tuple[int, int
skipped += 1
continue
_upsert_huya_account(db, parsed, tag=tag)
created_or_updated += 1
account = _upsert_huya_account(db, parsed, tag=tag)
if assign_to and account.assigned_to is None:
account.assigned_to = assign_to
accounts.append(account)
if created_or_updated:
if accounts:
db.commit()
return created_or_updated, skipped
for account in accounts:
db.refresh(account)
return accounts, skipped
def import_huya_cookies(db: Session, text: str, tag: str = "") -> tuple[int, int]:
"""导入虎牙 Cookie,返回 (成功数, 跳过数)。"""
accounts, skipped = import_huya_cookies_detailed(db, text, tag)
return len(accounts), skipped
def persist_huya_session_cookie(