feat(api): routes 完整(login + JWT 依赖 + optimize/factor + WS route)

This commit is contained in:
2026-07-06 19:04:26 +08:00
parent f5a69b312a
commit efaac41c06
3 changed files with 267 additions and 64 deletions
+22 -5
View File
@@ -2,19 +2,36 @@
FastAPI application factory for Sanguo Quant API
"""
from fastapi import FastAPI
from .routes import router, set_orchestrator
from .routes import router, set_orchestrator, set_auth_config
from .auth import set_jwt_config
from .ws import manager
from sanguo_orchestrator.runner import Orchestrator
def create_app(db_path: str, file_dir=None) -> FastAPI:
"""Create FastAPI application with orchestrator"""
def create_app(db_path: str, file_dir=None, auth_config=None, max_workers: int = 2) -> FastAPI:
"""Create FastAPI application with orchestrator and optional authentication"""
app = FastAPI(title="Sanguo Quant API")
# Initialize orchestrator
orch = Orchestrator(db_path=db_path, file_dir=file_dir)
orch = Orchestrator(db_path=db_path, file_dir=file_dir, max_workers=max_workers)
# Set up WebSocket stage callback
async def _on_stage(task_id, stage):
"""Broadcast stage updates to WebSocket subscribers"""
await manager.broadcast(task_id, {"task_id": task_id, "stage": stage})
orch.set_on_stage(_on_stage)
set_orchestrator(orch)
# Configure authentication if provided
if auth_config:
set_auth_config(auth_config)
set_jwt_config(
auth_config.get("jwt_secret", "x"),
auth_config.get("expire_minutes", 60)
)
# Include routes
app.include_router(router, prefix="/api/v1")
return app
return app