feat: 完善登录保持、栅格下载和任务调度
This commit is contained in:
+14
-6
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user