feat(huya): 外部 CK 协作台账(S1–S6)+ 图片上传能力
协作台账:新表 huya_external_orders 替代 Excel 多人协同表(设计见
docs/设计-虎牙外部CK协作台账.md),一条 CK 一行,所有人共享、改动留痕。
- 前端 pages/HuyaCollabPage.tsx + 菜单「虎牙 → 外部单协作」/huya/collab:
内联编辑(带乐观锁 version)、图片缩略图、详情抽屉(字段表单 + 两个图片槽位 +
操作时间线)、粘贴导入弹窗(带 TSV 预览)、批量/单条验证 CK、页头统计条、筛选
- 两套状态机:业务 pending→bound→recharged→scripted→done(旁路 void)、
凭据 unverified/valid/invalid/disabled;唯一写入口在 services/huya_collab_service.py,
字段级审计 + 整数 version 乐观锁(不用 updated_at:DATETIME 只到秒)
- CK 只读探针 check_user_bind_game_account(真机判据:响应非 None 且 status == 200),
成功即覆盖写绑定快照 bind_game_account/bind_game_role/bind_game_channel(迁移 0056),
失败只改凭据状态、不动业务状态;人工只能停用/恢复(POST /{id}/ck/status)
- 贴/换/重建 CK、TSV 批量导入(SAVEPOINT 单行隔离,部分失败不整体失败)、
权限 huya:collab:view/edit/manage(删除只给运营)
- 孤儿图清理脚本 scripts/cleanup_orphan_file_assets.py(默认 --dry-run)
图片上传(协作台账截图用):OSS/本地双后端 + 缩略图变体 + /api/files 代理回读,
权限 file:upload / file:view。
验证:pytest 880 passed / 6 skipped;ruff format 全绿、ruff check 仅剩既有告警;
前端 tsc -b / eslint / vite build 通过;接口端到端冒烟 29 项全绿(TestClient,探针用假客户端);
探针真机冒烟 3 例(有效 CK=True、别人 uid=False、裸 cookie=False)。
This commit is contained in:
@@ -414,11 +414,22 @@ def persist_huya_session_cookie(
|
||||
return True
|
||||
|
||||
|
||||
def rebuild_web_cookie_from_raw(db: Session, account: HuyaAccount) -> str:
|
||||
"""用 App 原始凭据重建网页运行 Cookie,不发起登录或支付。"""
|
||||
raw = normalize_huya_cookie(account.raw_cookie or "")
|
||||
def build_web_cookie_from_raw(
|
||||
*,
|
||||
uid: str = "",
|
||||
yyuid: str = "",
|
||||
username: str = "",
|
||||
raw_cookie: str = "",
|
||||
) -> str:
|
||||
"""用 App 原始凭据生成网页运行 Cookie(**纯函数,不碰数据库**)。
|
||||
|
||||
从 ``rebuild_web_cookie_from_raw`` 抽出来,供不依赖 ``huya_accounts`` 的调用方
|
||||
复用(例如虎牙外部 CK 协作台账)—— 与其把这段设备态补齐逻辑复制一份,
|
||||
不如让两边共用一处。原函数的行为一行未改,只是改为调用这里。
|
||||
"""
|
||||
raw = normalize_huya_cookie(raw_cookie or "")
|
||||
if not raw:
|
||||
raise ValueError("该账号没有 App 原始凭据,无法重建网页 Cookie")
|
||||
raise ValueError("没有 App 原始凭据,无法重建网页 Cookie")
|
||||
|
||||
from core.huya.cookie_utils import cookie_pairs
|
||||
from core.huya.device_profile import _load_db, canonical_account_key
|
||||
@@ -427,27 +438,37 @@ def rebuild_web_cookie_from_raw(db: Session, account: HuyaAccount) -> str:
|
||||
qimei_feature_from_device_profile,
|
||||
)
|
||||
|
||||
uid = 0
|
||||
for candidate in (account.uid, account.yyuid, cookie_value(raw, "udb_uid")):
|
||||
uid_value = 0
|
||||
for candidate in (uid, yyuid, cookie_value(raw, "udb_uid")):
|
||||
text = str(candidate or "").strip()
|
||||
if text.isdigit():
|
||||
uid = int(text)
|
||||
uid_value = int(text)
|
||||
break
|
||||
|
||||
feature = None
|
||||
username = (account.username or "").strip()
|
||||
if username:
|
||||
account_name = (username or "").strip()
|
||||
if account_name:
|
||||
profiles = _load_db()
|
||||
profile = profiles.get(canonical_account_key(username)) or profiles.get(
|
||||
username
|
||||
profile = profiles.get(canonical_account_key(account_name)) or profiles.get(
|
||||
account_name
|
||||
)
|
||||
if profile:
|
||||
feature = qimei_feature_from_device_profile(profile)
|
||||
|
||||
filled = fill_web_cookie_fields(raw, guid="", uid=uid, qimei_feature=feature)
|
||||
filled = fill_web_cookie_fields(raw, guid="", uid=uid_value, qimei_feature=feature)
|
||||
pairs = dict(cookie_pairs(filled))
|
||||
pairs["udb_appid"] = "5002"
|
||||
rebuilt = "; ".join(f"{key}={value}" for key, value in pairs.items())
|
||||
return "; ".join(f"{key}={value}" for key, value in pairs.items())
|
||||
|
||||
|
||||
def rebuild_web_cookie_from_raw(db: Session, account: HuyaAccount) -> str:
|
||||
"""用 App 原始凭据重建网页运行 Cookie,不发起登录或支付。"""
|
||||
rebuilt = build_web_cookie_from_raw(
|
||||
uid=account.uid,
|
||||
yyuid=account.yyuid,
|
||||
username=account.username,
|
||||
raw_cookie=account.raw_cookie,
|
||||
)
|
||||
account.cookie = rebuilt
|
||||
account.status = "login_success"
|
||||
account.updated_at = datetime.now(UTC)
|
||||
|
||||
Reference in New Issue
Block a user