fix(api): 限制上传文件大小为8MB

- 后端新增中间件限制请求体最大为8MB,超出返回413错误
- nginx配置添加client_max_body_size为8m以支持8MB最大上传
- 更新favicon.svg图标样式
- 模型列表页默认分页大小由10改为50,提高一次加载条目数
This commit is contained in:
yangy
2026-05-25 13:25:05 +08:00
parent fb1aad45af
commit abab985769
4 changed files with 27 additions and 4 deletions
+18 -1
View File
@@ -1,5 +1,6 @@
from fastapi import FastAPI, Depends
from fastapi import FastAPI, Depends, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import os
import logging
from dotenv import load_dotenv
@@ -39,6 +40,22 @@ app = FastAPI(
version="1.0.0"
)
# 限制请求体最大 8MB
MAX_BODY_SIZE = 8 * 1024 * 1024 # 8MB
@app.middleware("http")
async def limit_body_size(request: Request, call_next):
content_length = request.headers.get("content-length")
if content_length and int(content_length) > MAX_BODY_SIZE:
return JSONResponse(
status_code=413,
content={"detail": "上传文件大小超过 8MB 限制"},
)
response = await call_next(request)
return response
# Configure CORS
app.add_middleware(
CORSMiddleware,