Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43e06b7d0f |
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "videosdowntools",
|
||||
"private": true,
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"scripts": {
|
||||
"tauri": "tauri"
|
||||
},
|
||||
|
||||
@@ -15,7 +15,7 @@ import httpx
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
API = "https://git.asio.asia/api/v1/repos/nixevol/RaptDramaDump"
|
||||
ASSET = ROOT / "dist" / "VideosDownTools-windows-x64.zip"
|
||||
NOTES = "导出 DramaBox 登录凭据时会弹出保存窗口。"
|
||||
NOTES = "导入 DramaBox 凭据后会先读取个人信息,确认登录成功后才进入。"
|
||||
PART_SIZE = 40 * 1024 * 1024
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "VideosDownTools",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"identifier": "com.videosdowntools.desktop",
|
||||
"build": {
|
||||
"beforeDevCommand": {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from server.services.dramabox.app_api import account_from_bootstrap
|
||||
from server.services.dramabox.login import _credential_record
|
||||
|
||||
|
||||
@@ -35,6 +36,27 @@ def test_credential_file_is_one_json_document() -> None:
|
||||
raise AssertionError("不完整的凭据文件应被拒绝")
|
||||
|
||||
|
||||
def test_account_profile_must_match_the_credential() -> None:
|
||||
app = {"user_id": "88", "token": "Bearer old"}
|
||||
fresh = account_from_bootstrap(app, {"user": {"uid": "88", "token": "new", "nickname": "阿花", "isVip": 1}})
|
||||
assert fresh["token"] == "Bearer new"
|
||||
assert fresh["name"] == "阿花"
|
||||
assert fresh["vip"] is True
|
||||
try:
|
||||
account_from_bootstrap(app, {"user": {"uid": "99", "token": "new", "nickname": "别人"}})
|
||||
except RuntimeError as exc:
|
||||
assert "失效" in str(exc)
|
||||
else:
|
||||
raise AssertionError("用户编号不一致应视为未登录")
|
||||
try:
|
||||
account_from_bootstrap(app, {})
|
||||
except RuntimeError as exc:
|
||||
assert "失效" in str(exc)
|
||||
else:
|
||||
raise AssertionError("没有个人信息应视为未登录")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_credential_file_is_one_json_document()
|
||||
test_account_profile_must_match_the_credential()
|
||||
print("ok")
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "videosdowntools-ui",
|
||||
"private": true,
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
Reference in New Issue
Block a user