From 617e37788bc244fe287b8f7bb130c1288067cca8 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 25 Oct 2026 07:12:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=AD=E6=9C=9F=E5=8F=91=E7=8E=B0?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=A4=B1=E6=95=88=E6=97=B6=E6=9A=82=E5=81=9C?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/platform/keepalive.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/app/platform/keepalive.py b/backend/app/platform/keepalive.py index 96561fd..8623fb6 100644 --- a/backend/app/platform/keepalive.py +++ b/backend/app/platform/keepalive.py @@ -5,6 +5,7 @@ from __future__ import annotations import asyncio import logging +from app.platform.client import NqiAuthError, NqiError from app.platform.sessions import remember_account from app.shared.state import state @@ -14,9 +15,16 @@ INTERVAL_SECONDS = 180 async def refresh_saved_session() -> None: client = state.client - if client is None or state.user is None: + if client is None or state.user is None or state.expired: + return + try: + refreshed = await client.touch_session() + except NqiAuthError as exc: + state.on_session_expired(str(exc) or "登录已失效,请重新登录") + return + except NqiError as exc: + logger.info("登录续期未完成: %s", exc) return - refreshed = await client.touch_session() state.user = refreshed await remember_account(refreshed, client.export_cookies()) @@ -26,5 +34,7 @@ async def session_keepalive() -> None: await asyncio.sleep(INTERVAL_SECONDS) try: await refresh_saved_session() + except NqiAuthError as exc: + state.on_session_expired(str(exc) or "登录已失效,请重新登录") except Exception as exc: logger.info("登录续期未完成: %s", exc)