fix: 导入 DramaBox 凭据后先核对个人信息

This commit is contained in:
Nixevol
2026-10-29 21:20:28 +08:00
parent f6274c6ff6
commit 43e06b7d0f
7 changed files with 110 additions and 47 deletions
+32
View File
@@ -72,6 +72,38 @@ def create_guest(template: dict | None = None) -> dict:
return _guest_from_bootstrap(device, data)
def refresh_account(app: dict) -> dict:
if not isinstance(app, dict):
raise RuntimeError("登录凭据已失效")
data = _post("drama-box/ap001/bootstrap", {
"distinctId": str(app.get("instance_id") or uuid.uuid4()),
"installTime": str(app.get("install_time") or int(time.time() * 1000)),
}, app)
return account_from_bootstrap(app, data)
def account_from_bootstrap(app: dict, data: dict) -> dict:
user = data.get("user") if isinstance(data, dict) else None
if not isinstance(user, dict):
raise RuntimeError("登录凭据已失效")
uid = str(user.get("uid") or user.get("userId") or "").strip()
token = str(user.get("token") or "").strip()
if not uid or uid == "0" or not token:
raise RuntimeError("登录凭据已失效")
expected = str((app or {}).get("user_id") or "").strip()
if expected and uid != expected:
raise RuntimeError("登录凭据已失效")
if not token.startswith("Bearer "):
token = f"Bearer {token}"
nickname = ""
for key in ("nickname", "nickName", "name", "userName"):
nickname = str(user.get(key) or "").strip()
if nickname:
break
vip = user.get("isVip") in (1, True) or str(user.get("isVip") or "").lower() in {"1", "true", "y"}
return {"user_id": uid, "token": token, "name": nickname, "vip": vip}
def ensure_guest() -> dict:
if client.has_guest():
return client.guest