diff --git a/backend/main.py b/backend/main.py index df9620c..65dd5d6 100644 --- a/backend/main.py +++ b/backend/main.py @@ -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, diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 406f682..18714a1 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -15,6 +15,9 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + + # 允许上传最大 8MB 的文件 + client_max_body_size 8m; } # Handle Vue Router history mode diff --git a/frontend/public/favicon.svg b/frontend/public/favicon.svg index f06ddef..017b56c 100644 --- a/frontend/public/favicon.svg +++ b/frontend/public/favicon.svg @@ -1,3 +1,6 @@ - - < + + + + + diff --git a/frontend/src/views/model/index.vue b/frontend/src/views/model/index.vue index 29c8feb..7c6110e 100644 --- a/frontend/src/views/model/index.vue +++ b/frontend/src/views/model/index.vue @@ -343,7 +343,7 @@ const searchForm = reactive({ const pagination = reactive({ page: 1, - pageSize: 10, + pageSize: 50, total: 0 })