High priority: - Fix concurrent race condition for view_count/like_count (atomic update) - Add route request ID tracking to prevent race conditions - Filter get_joke by status=approved (no pending content leak) - Add error feedback for like button Performance: - Optimize random joke query (avoid full table sort) - Limit page_size max to 100 (DoS prevention) Medium: - Add localStorage quota error handling - Handle empty AI response gracefully - Fix generate content title extraction Low: - Add rejected_jokes to stats API - Update dashboard to show rejected count
39 lines
1.1 KiB
Plaintext
39 lines
1.1 KiB
Plaintext
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import API_TITLE, API_VERSION
|
|
from app.routers import jokes_router, categories_router, auth_router, admin_router, settings_router
|
|
from app.database import Base, engine
|
|
from app.models.setting import AiSetting # 注册模型,确保 create_all 能看到
|
|
|
|
# 创建新表(如果不存在)
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
# Create FastAPI application
|
|
app = FastAPI(title=API_TITLE, version=API_VERSION)
|
|
|
|
# Configure CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Mount routers
|
|
app.include_router(jokes_router, prefix="/api")
|
|
app.include_router(categories_router, prefix="/api")
|
|
app.include_router(auth_router, prefix="/api")
|
|
app.include_router(admin_router, prefix="/api")
|
|
app.include_router(settings_router, prefix="/api")
|
|
|
|
|
|
@app.get("/")
|
|
def root():
|
|
return {"message": "欢迎使用笑话大全 API"}
|
|
|
|
|
|
@app.get("/health")
|
|
def health_check():
|
|
return {"status": "healthy"} |