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
+52 -43
View File
@@ -23,43 +23,7 @@ def enter(language: str = "") -> dict:
def import_adb(serial: str, language: str = "") -> dict:
from server.services.dramabox.app_device import read_app_login
record = read_app_login(serial)
try:
locale = resolve(language or record.get("language") or client.language or DEFAULT_LANGUAGE)
except RuntimeError:
locale = resolve(DEFAULT_LANGUAGE)
if not client.token:
client.token = secrets.token_hex(16)
client.language = locale["id"]
client.app = {key: value for key, value in record.items() if key not in {"name", "vip"}}
client.app["language"] = locale["id"]
client.app["current_language"] = locale["id"]
nickname = str(record.get("name") or record.get("user_id") or "DramaBox")
client.profile = {
"id": record.get("user_id") or "",
"username": nickname,
"nickname": nickname,
"email": "",
"phone": "",
"badge": "VIP" if record.get("vip") else "",
"vipday": 1 if record.get("vip") else 0,
"score": 0,
"watched": 0,
"rewards": 0,
"login_day": 0,
"country": locale.get("country") or "",
"language": locale.get("language") or "",
"native": locale.get("native") or "",
"locale": locale.get("id") or "",
"loginType": "app",
"has_login": "1",
"app_login": "1",
"avatarNumUrl": "",
}
client.save()
from server.services.dramabox.app_api import ensure_guest
ensure_guest()
return {"token": client.token, "profile": client.profile}
return _install_app_login(read_app_login(serial), language)
_CREDENTIAL_KIND = "dramabox-login"
@@ -159,19 +123,68 @@ if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
def import_credential(payload: dict, language: str = "") -> dict:
record = _credential_record(payload)
return _install_app_login(_credential_record(payload), language)
def _install_app_login(record: dict, language: str = "") -> dict:
try:
locale = resolve(language or record.get("language") or client.language or DEFAULT_LANGUAGE)
except RuntimeError:
locale = resolve(DEFAULT_LANGUAGE)
previous = {
"token": client.token,
"language": client.language,
"app": dict(client.app),
"profile": dict(client.profile) if isinstance(client.profile, dict) else {},
}
if not client.token:
client.token = secrets.token_hex(16)
client.language = locale["id"]
client.app = {key: value for key, value in record.items() if key not in {"name", "vip"}}
client.app["language"] = locale["id"]
client.app["current_language"] = locale["id"]
client.profile = _profile_from_record(record, locale)
client.save()
try:
_confirm_account(locale)
except RuntimeError:
client.token = previous["token"]
client.language = previous["language"]
client.app = previous["app"]
client.profile = previous["profile"]
client.save()
raise
from server.services.dramabox.app_api import ensure_guest
ensure_guest()
return {"token": client.token, "profile": client.profile}
def _confirm_account(locale: dict) -> None:
from server.services.dramabox.app_api import refresh_account
try:
fresh = refresh_account(client.app)
except RuntimeError as exc:
text = str(exc).strip()
if "失效" in text:
raise
if any(word in text for word in ("拦截", "没有响应", "没有返回", "网络")):
raise RuntimeError("暂时读不到个人信息,请检查网络后再导入") from exc
raise RuntimeError("登录凭据已失效") from exc
if fresh.get("token"):
client.app["token"] = fresh["token"]
if fresh.get("user_id"):
client.app["user_id"] = fresh["user_id"]
record = dict(client.app)
record["name"] = fresh.get("name") or ""
record["vip"] = fresh.get("vip") is True
client.profile = _profile_from_record(record, locale)
client.save()
def _profile_from_record(record: dict, locale: dict) -> dict:
nickname = str(record.get("name") or record.get("user_id") or "DramaBox")
client.profile = {
return {
"id": record.get("user_id") or "",
"username": nickname,
"nickname": nickname,
@@ -192,10 +205,6 @@ def import_credential(payload: dict, language: str = "") -> dict:
"app_login": "1",
"avatarNumUrl": "",
}
client.save()
from server.services.dramabox.app_api import ensure_guest
ensure_guest()
return {"token": client.token, "profile": client.profile}
def _credential_record(payload: dict) -> dict: