fix(P1): Hydro v5.8 会话 cookie 名 sid+sid.sig(非 _sid);登录异常转业务错误

这个提交包含在:
langxm
2026-10-13 20:18:51 +08:00
父节点 2d929ee529
当前提交 69058e80d3
共修改 5 个文件,包含 22 行新增和 15 行删除
+9 -5
查看文件
@@ -92,8 +92,8 @@ class HydroAdmin:
m = re.search(r'name="_csrf"\s+value="([^"]+)"', html_text, re.I)
return unescape(m.group(1)) if m else ""
async def login(self, uname: str, password: str) -> str:
"""登录 Hydro,返回 _sid cookie 字符串;失败抛 ValueError。"""
async def login(self, uname: str, password: str) -> dict[str, str]:
"""登录 Hydro,返回会话 cookie 字典(v5.8: sid + sid.sig;旧版兼容 _sid)。"""
async with httpx.AsyncClient(
base_url=self.base_url, timeout=30, follow_redirects=True,
headers={"User-Agent": UA, "Accept": "text/html,application/json,*/*"},
@@ -109,7 +109,11 @@ class HydroAdmin:
text = r.text
if "用户名或密码错误" in text or "Invalid" in text:
raise ValueError("Hydro 登录失败:用户名或密码错误")
sid = client.cookies.get("_sid")
if not sid:
cookies: dict[str, str] = {}
for name in ("sid", "sid.sig", "_sid"):
val = client.cookies.get(name)
if val:
cookies[name] = val
if not cookies:
raise ValueError("Hydro 登录失败:未获取到会话 cookie")
return sid
return cookies