清理项目配置文件,移除不再使用的.idea文件和更新文档中的Python版本要求

This commit is contained in:
2025-12-17 16:15:47 +08:00
parent 8ce34440d8
commit 35efbdf000
27 changed files with 123 additions and 221 deletions

17
app.py
View File

@@ -1,6 +1,6 @@
from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi import Request, HTTPException
from fastapi import Request
from contextlib import asynccontextmanager
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
@@ -11,6 +11,7 @@ from routes import (session, admin, object)
from model.database import Database
import os
import pkg.conf
from pkg import utils
from loguru import logger
@@ -54,21 +55,21 @@ app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
@app.get("/")
def read_root():
async def frontend_index():
if not os.path.exists("dist/index.html"):
raise HTTPException(status_code=404)
utils.raise_not_found("Index not found")
return FileResponse("dist/index.html")
# 回退路由
@app.get("/{path:path}")
async def serve_spa(request: Request, path: str):
async def frontend_path(path: str):
if not os.path.exists("dist/index.html"):
raise HTTPException(status_code=404)
utils.raise_not_found("Index not found, please build frontend first.")
# 排除API路由
if path.startswith("api/"):
raise HTTPException(status_code=404)
utils.raise_not_found("API route not found")
# 检查是否是静态资源请求
if path.startswith("assets/") and os.path.exists(f"dist/{path}"):
return FileResponse(f"dist/{path}")