feat: 完善登录保持、栅格下载和任务调度

This commit is contained in:
2026-10-25 05:42:24 +08:00
parent dab26ff4ee
commit 4cf64957c5
25 changed files with 1871 additions and 320 deletions
+14 -6
View File
@@ -1,12 +1,14 @@
"""本机接口。只监听 127.0.0.1。功能路由按目录挂上。"""
from contextlib import asynccontextmanager
import asyncio
from contextlib import asynccontextmanager, suppress
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.features.download.router import router as download_router
from app.platform.auth import router as auth_router
from app.platform.keepalive import session_keepalive
from app.shared.state import state
ORIGINS = [
@@ -20,11 +22,17 @@ ORIGINS = [
@asynccontextmanager
async def lifespan(_app: FastAPI):
yield
if state.client is not None:
await state.client.aclose()
for client, _challenge in state.flows.values():
await client.aclose()
keepalive = asyncio.create_task(session_keepalive())
try:
yield
finally:
keepalive.cancel()
with suppress(asyncio.CancelledError):
await keepalive
if state.client is not None:
await state.client.aclose()
for client, _challenge in state.flows.values():
await client.aclose()
app = FastAPI(title="NqiTools", lifespan=lifespan)