引入二级大纲功能,新增父子节点关系及子节点排序,同时调整API与UI以支持嵌套大纲管理

This commit is contained in:
2026-03-22 16:53:33 +08:00
parent 20c759150a
commit 098ff4e16d
33 changed files with 2516 additions and 381 deletions

View File

@@ -1,7 +1,10 @@
from contextlib import asynccontextmanager
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from starlette.responses import FileResponse
from .database import init_db
from .routers.novels import router as novels_router
@@ -12,6 +15,9 @@ from .routers.world_setting import router as world_setting_router
from .routers.ai_config import router as ai_config_router
from .routers.chat import router as chat_router
# 前端构建产物目录Docker 中为 /app/static本地开发时不存在则跳过
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
@asynccontextmanager
async def lifespan(app: FastAPI):
@@ -23,7 +29,7 @@ app = FastAPI(title="Noval", version="0.1.0", lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"],
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
@@ -41,3 +47,17 @@ app.include_router(chat_router)
@app.get("/api/health")
def health():
return {"status": "ok"}
# 生产环境serve 前端静态文件Vue SPA
if STATIC_DIR.is_dir():
# 静态资源js/css/img
app.mount("/assets", StaticFiles(directory=STATIC_DIR / "assets"), name="assets")
# 所有非 /api 路径返回 index.htmlVue Router history 模式)
@app.get("/{path:path}")
async def spa_fallback(path: str):
file_path = STATIC_DIR / path
if file_path.is_file():
return FileResponse(file_path)
return FileResponse(STATIC_DIR / "index.html")