- 支持 MiniMax/OpenAI/Google Gemini/智谱/Kimi 五个平台 - 插件化 Provider 架构,自动发现注册 - 多维度 QuotaRule 额度追踪(固定间隔/自然周期/API同步/手动) - OpenAI + Anthropic 兼容 API 代理,SSE 流式转发 - Model 路由表 + 额度耗尽自动 fallback - 多媒体任务队列(图片/语音/视频) - Vue3 + Tailwind 单文件 Web 仪表盘 - Docker 一键部署 Made-with: Cursor
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
"""FastAPI 应用入口"""
|
|
|
|
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import FileResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from app.config import settings
|
|
from app.database import get_db, close_db, seed_from_config
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
await get_db()
|
|
await seed_from_config()
|
|
|
|
from app.services.scheduler import start_scheduler
|
|
await start_scheduler()
|
|
|
|
Path(settings.storage.path).mkdir(parents=True, exist_ok=True)
|
|
|
|
yield
|
|
|
|
from app.services.scheduler import stop_scheduler
|
|
await stop_scheduler()
|
|
await close_db()
|
|
|
|
|
|
app = FastAPI(
|
|
title="Plan Manager",
|
|
description="多平台 Coding Plan 统一管理系统",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# 挂载 API / 代理路由
|
|
from app.routers import plans, quota, queue, proxy # noqa: E402
|
|
|
|
app.include_router(plans.router, prefix="/api/plans", tags=["Plans"])
|
|
app.include_router(quota.router, prefix="/api/quota", tags=["Quota"])
|
|
app.include_router(queue.router, prefix="/api/queue", tags=["Queue"])
|
|
app.include_router(proxy.router, tags=["Proxy"])
|
|
|
|
# 前端: 用显式路由而非 mount("/") 以避免遮盖 /docs, /api, /v1
|
|
_static_dir = Path(__file__).parent / "static"
|
|
|
|
|
|
@app.get("/", include_in_schema=False)
|
|
async def serve_index():
|
|
return FileResponse(_static_dir / "index.html")
|