From fd9b15551877194092f08fe95acee1189fe98afa Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 25 Oct 2026 06:08:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=BB=84=E8=B1=86=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E7=AD=BE=E5=88=B0=E9=A2=86=E7=A7=AF?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/services/huangdou/api.py | 10 ++++++ server/services/huangdou/login.py | 52 +++++++++++++++++++++++++++++-- tests/test_huangdou_coins.py | 14 +++++++++ ui/src/App.vue | 10 ++++++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/server/services/huangdou/api.py b/server/services/huangdou/api.py index ab3c073..32d92ee 100644 --- a/server/services/huangdou/api.py +++ b/server/services/huangdou/api.py @@ -73,6 +73,16 @@ def login_username(username: str, password: str, channel_code: str = "") -> dict return data +def user_sign() -> dict: + data = client.request("/user/sign", {}, auth=True, identity="account") + return data if isinstance(data, dict) else {} + + +def user_do_sign() -> dict: + data = client.request("/user/doSign", {}, auth=True, identity="account") + return data if isinstance(data, dict) else {} + + def user_info(*, identity: str = "guest") -> dict: data = client.request("/user/info", {}, auth=True, identity=identity) if not isinstance(data, dict): diff --git a/server/services/huangdou/login.py b/server/services/huangdou/login.py index 44b563d..b1741d1 100644 --- a/server/services/huangdou/login.py +++ b/server/services/huangdou/login.py @@ -44,7 +44,8 @@ def login_account(username: str, password: str, rotate_fingerprint: bool = False client.profile = profile client.save() api.remember_api_lines() - return {"token": client.token, "profile": profile} + sign = claim_daily_sign() + return {"token": client.token, "profile": client.profile, "sign": sign} def resume() -> dict: @@ -63,7 +64,54 @@ def current(token: str) -> dict: profile = public_profile(account) client.profile = profile client.save() - return {"token": client.token, "profile": profile} + sign = claim_daily_sign() + return {"token": client.token, "profile": client.profile, "sign": sign} + + +def claim_daily_sign() -> dict | None: + if not client.account_token: + return None + try: + status = api.user_sign() + except (TokenExpired, RuntimeError): + return None + if _signed_today(status.get("today_signed") if isinstance(status, dict) else None): + return None + try: + result = api.user_do_sign() + except (TokenExpired, RuntimeError): + return None + if not isinstance(result, dict): + result = {} + balance = result.get("balance") + if balance not in (None, "") and isinstance(client.profile, dict): + client.profile["balance"] = balance + client.profile["score"] = _number(balance) + client.save() + return {"message": _sign_message(result)} + + +def _signed_today(value) -> bool: + if isinstance(value, bool): + return value + if isinstance(value, (int, float)) and not isinstance(value, bool): + return value != 0 + text = str(value or "").strip().lower() + return text in {"y", "1", "true", "yes"} + + +def _sign_message(result: dict) -> str: + name = str(result.get("prize_name") or "").strip() + try: + amount = int(float(str(result.get("prize_num") or "0"))) + except (TypeError, ValueError): + amount = 0 + if amount > 0 and name: + return f"签到成功,获得 {name} × {amount}" + if amount > 0: + return f"签到成功,获得 {amount} 积分" + text = str(result.get("msg") or "").strip() + return text or "签到成功" def account_balance() -> int: diff --git a/tests/test_huangdou_coins.py b/tests/test_huangdou_coins.py index 8e98986..a94529a 100644 --- a/tests/test_huangdou_coins.py +++ b/tests/test_huangdou_coins.py @@ -115,6 +115,19 @@ def test_saved_accounts_roundtrip() -> None: assert accounts_module.load()[0]["password"] == "secret-one" +def test_sign_only_when_today_is_open() -> None: + from server.services.huangdou.login import _sign_message, _signed_today + + assert not _signed_today(None) + assert not _signed_today("n") + assert not _signed_today("0") + assert _signed_today("y") + assert _signed_today("Y") + assert _signed_today(True) + assert _sign_message({"prize_name": "金币", "prize_num": 10}) == "签到成功,获得 金币 × 10" + assert _sign_message({"msg": "已经签过了"}) == "已经签过了" + + def test_host_keeps_scheme() -> None: assert normalize_host("pmihlvee.cc") == "https://pmihlvee.cc" assert normalize_host("https://example.com/") == "https://example.com" @@ -126,5 +139,6 @@ if __name__ == "__main__": test_payment_and_episode_choice() test_account_login_reuses_the_same_device_fingerprint() test_saved_accounts_roundtrip() + test_sign_only_when_today_is_open() test_host_keeps_scheme() print("ok") diff --git a/ui/src/App.vue b/ui/src/App.vue index 066e99f..f94d69e 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -140,6 +140,7 @@ const dramaboxLangs = ref<{ label: string; value: string }[]>([]); const accountBusy = ref(false); const activeProxyUrl = ref(""); const profileError = ref(""); +const signNotice = ref(""); const method = ref("guest"); const email = ref(""); const password = ref(""); @@ -1035,6 +1036,7 @@ async function loginHuangdou(asGuest = false) { } token.value = payload.token; profile.value = payload.profile; + takeSign(payload); writeSavedToken(payload.token); page.value = "download"; startLive(); @@ -1194,6 +1196,11 @@ function applyLive(payload: { downloads?: { active: LiveJob[]; done: LiveJob[]; if (payload.profile) profile.value = payload.profile; } +function takeSign(payload: { sign?: { message?: string } | null }) { + const message = payload.sign?.message?.trim() || ""; + if (message) signNotice.value = message; +} + function startLive() { stopLive(); const protocol = location.protocol === "https:" ? "wss" : "ws"; @@ -1345,6 +1352,7 @@ onMounted(async () => { const payload = await response.json(); token.value = payload.token; profile.value = payload.profile; + takeSign(payload); rememberSessionDevice(payload.device); page.value = "download"; startLive(); @@ -1412,6 +1420,7 @@ onUnmounted(stopLive);
返回 {{ pageTitle }} + {{ signNotice }}