feat: 保留 DramaBox 登录,只有手动退出才清除
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import secrets
|
||||
|
||||
from server.services.dramabox.client import client
|
||||
from server.services.dramabox.locales import DEFAULT_LANGUAGE, public_list
|
||||
from server.services.dramabox.locales import DEFAULT_LANGUAGE, public_list, resolve
|
||||
|
||||
|
||||
def languages() -> list[dict]:
|
||||
@@ -16,7 +18,13 @@ def apply_account(language: str, user: dict) -> dict:
|
||||
web_token = str(user.get("token") or "").strip()
|
||||
if not web_token or not _logged_in(user.get("isLogin")):
|
||||
raise RuntimeError("还没有登录成功")
|
||||
locale = client.enter(language or client.language or DEFAULT_LANGUAGE)["profile"]
|
||||
try:
|
||||
locale = resolve(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.web_token = web_token
|
||||
profile = _account_profile(locale, user)
|
||||
client.profile = profile
|
||||
@@ -69,6 +77,12 @@ def _number(value) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def resume() -> dict:
|
||||
if not client.token or not client.profile:
|
||||
raise RuntimeError("还没有登录")
|
||||
return {"token": client.token, "profile": client.profile}
|
||||
|
||||
|
||||
def current(token: str) -> dict:
|
||||
token = (token or "").strip()
|
||||
if not token:
|
||||
|
||||
@@ -25,6 +25,12 @@ def enter() -> dict:
|
||||
return {"token": client.token, "profile": profile}
|
||||
|
||||
|
||||
def resume() -> dict:
|
||||
if not client.token or not client.profile:
|
||||
raise RuntimeError("还没有登录")
|
||||
return {"token": client.token, "profile": client.profile}
|
||||
|
||||
|
||||
def current(token: str) -> dict:
|
||||
token = (token or "").strip()
|
||||
if not token:
|
||||
|
||||
Reference in New Issue
Block a user