feat: 黄豆登录后自动签到领积分
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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<Method>("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);
|
||||
<div class="bar-title">
|
||||
<n-button v-if="page === 'play'" quaternary size="small" @click="closePlay">返回</n-button>
|
||||
<n-text strong class="bar-title-text">{{ pageTitle }}</n-text>
|
||||
<n-text v-if="signNotice" class="sign-note">{{ signNotice }}</n-text>
|
||||
</div>
|
||||
<div v-if="page === 'download'" class="bar-search">
|
||||
<n-input
|
||||
@@ -1864,6 +1873,7 @@ html { color-scheme: dark; }
|
||||
}
|
||||
.bar-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
||||
.bar-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.sign-note { flex: none; color: #63e2b7; font-size: 13px; white-space: nowrap; }
|
||||
.bar-search {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
|
||||
Reference in New Issue
Block a user