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.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import os import os
import logging import logging
from dotenv import load_dotenv from dotenv import load_dotenv
@@ -39,6 +40,22 @@ app = FastAPI(
version="1.0.0" 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 # Configure CORS
app.add_middleware( app.add_middleware(
CORSMiddleware, CORSMiddleware,
+3
View File
@@ -15,6 +15,9 @@ server {
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
# 允许上传最大 8MB 的文件
client_max_body_size 8m;
} }
# Handle Vue Router history mode # Handle Vue Router history mode
+5 -2
View File
@@ -1,3 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 36 36">
<text y="0.88em" x="50" text-anchor="middle" font-size="72"><§</text> <path d="M0 0h36v36H0z" fill="none" />
<path fill="#66757f" d="M18 0C9.716 0 3 6.716 3 15v9h3v-9C6 8 11.269 2.812 18 2.812S30 8 30 15v10l3-1v-9c0-8.284-6.716-15-15-15" />
<path fill="#31373d" d="M6 27a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-9a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2zm30 0a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2v-9a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2z" />
<path fill="#55acee" d="m19.182 10.016l-6.364 1.313c-.45.093-.818.544-.818 1.004v16.185a6.2 6.2 0 0 0-2.087-.36c-2.785 0-5.042 1.755-5.042 3.922c0 2.165 2.258 3.827 5.042 3.827C12.649 35.905 14.922 34 15 32V16.39l4.204-.872c.449-.093.796-.545.796-1.004v-3.832c0-.458-.368-.759-.818-.666m8 3.151l-4.297.865c-.45.093-.885.544-.885 1.003V26.44c0-.152-.878-.24-1.4-.24c-2.024 0-3.633 1.276-3.633 2.852c0 1.574 1.658 2.851 3.683 2.851s3.677-1.277 3.677-2.851l-.014-11.286l2.869-.598c.45-.093.818-.544.818-1.003v-2.33c0-.459-.368-.76-.818-.668" />
</svg> </svg>

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 978 B

+1 -1
View File
@@ -343,7 +343,7 @@ const searchForm = reactive({
const pagination = reactive({ const pagination = reactive({
page: 1, page: 1,
pageSize: 10, pageSize: 50,
total: 0 total: 0
}) })