feat(huya): 多选登录改单线程队列并拆分路由与工作台
默认同时只登一个号,失败两次跳下一个,号间留间隔,结束后可一键重试失败账号。 顺带拆分虎牙路由与斗鱼工作台页面,并补齐 raw_cookie 重建入口。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -369,6 +369,74 @@ def import_huya_cookies(db: Session, text: str, tag: str = "") -> tuple[int, int
|
||||
return created_or_updated, skipped
|
||||
|
||||
|
||||
def persist_huya_session_cookie(
|
||||
db: Session,
|
||||
account_id: int,
|
||||
original_cookie: str,
|
||||
filled_cookie: str,
|
||||
) -> bool:
|
||||
"""把活动会话补齐后的网页 Cookie 回写到账号。
|
||||
|
||||
原始登录态只有 App 字段时,wsLaunch 会补齐 guid 等网页设备字段;
|
||||
不回写则下次任务又会重新生成设备态。
|
||||
"""
|
||||
filled = normalize_huya_cookie(filled_cookie or "")
|
||||
original = normalize_huya_cookie(original_cookie or "")
|
||||
if not filled or filled == original:
|
||||
return False
|
||||
account = db.query(HuyaAccount).filter(HuyaAccount.id == account_id).first()
|
||||
if account is None:
|
||||
return False
|
||||
if normalize_huya_cookie(account.cookie or "") == filled:
|
||||
return False
|
||||
account.cookie = filled
|
||||
account.updated_at = datetime.now(UTC)
|
||||
db.commit()
|
||||
return True
|
||||
|
||||
|
||||
def rebuild_web_cookie_from_raw(db: Session, account: HuyaAccount) -> str:
|
||||
"""用 App 原始凭据重建网页运行 Cookie,不发起登录或支付。"""
|
||||
raw = normalize_huya_cookie(account.raw_cookie or "")
|
||||
if not raw:
|
||||
raise ValueError("该账号没有 App 原始凭据,无法重建网页 Cookie")
|
||||
|
||||
from core.huya.cookie_utils import cookie_pairs
|
||||
from core.huya.device_profile import _load_db, canonical_account_key
|
||||
from core.huya.web_cookie_fields import (
|
||||
fill_web_cookie_fields,
|
||||
qimei_feature_from_device_profile,
|
||||
)
|
||||
|
||||
uid = 0
|
||||
for candidate in (account.uid, account.yyuid, cookie_value(raw, "udb_uid")):
|
||||
text = str(candidate or "").strip()
|
||||
if text.isdigit():
|
||||
uid = int(text)
|
||||
break
|
||||
|
||||
feature = None
|
||||
username = (account.username or "").strip()
|
||||
if username:
|
||||
profiles = _load_db()
|
||||
profile = profiles.get(canonical_account_key(username)) or profiles.get(
|
||||
username
|
||||
)
|
||||
if profile:
|
||||
feature = qimei_feature_from_device_profile(profile)
|
||||
|
||||
filled = fill_web_cookie_fields(raw, guid="", uid=uid, qimei_feature=feature)
|
||||
pairs = dict(cookie_pairs(filled))
|
||||
pairs["udb_appid"] = "5002"
|
||||
rebuilt = "; ".join(f"{key}={value}" for key, value in pairs.items())
|
||||
account.cookie = rebuilt
|
||||
account.status = "login_success"
|
||||
account.updated_at = datetime.now(UTC)
|
||||
db.commit()
|
||||
db.refresh(account)
|
||||
return account.cookie
|
||||
|
||||
|
||||
def ensure_huya_config(db: Session) -> HuyaConfig:
|
||||
"""获取单条虎牙配置,不存在则创建。"""
|
||||
config = db.query(HuyaConfig).first()
|
||||
|
||||
Reference in New Issue
Block a user