From fa59dcc05dff5e6a54362ab23ca855172e408185 Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Tue, 23 Dec 2025 19:10:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/files.py | 8 +++++++- docker-compose.yml | 4 ++++ forntend/nginx.conf | 9 +++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/backend/app/api/v1/files.py b/backend/app/api/v1/files.py index f98073b..bd6103a 100644 --- a/backend/app/api/v1/files.py +++ b/backend/app/api/v1/files.py @@ -9,6 +9,7 @@ from typing import List import os import zipfile import io +import mimetypes from pathlib import Path from app.core.database import get_db @@ -217,11 +218,16 @@ async def get_asset_file( if not file_path.exists() or not file_path.is_file(): raise HTTPException(status_code=404, detail="文件不存在") + # 根据文件扩展名确定 MIME 类型 + mime_type, _ = mimetypes.guess_type(filename) + if mime_type is None: + mime_type = "application/octet-stream" + # 返回文件(流式响应) return FileResponse( path=file_path, filename=filename, - media_type="application/octet-stream" + media_type=mime_type ) diff --git a/docker-compose.yml b/docker-compose.yml index 5bbe1f5..bd53432 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -63,6 +63,10 @@ services: - REDIS_DB=${REDIS_DB:-8} - SECRET_KEY=${SECRET_KEY:-your-secret-key-change-me-in-production} - DEBUG=${DEBUG:-false} + - ADMIN_USERNAME=${ADMIN_USERNAME:-admin} + - ADMIN_PASSWORD=${ADMIN_PASSWORD:-Admin@123456} + - ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example.com} + - ADMIN_NICKNAME=${ADMIN_NICKNAME:-系统管理员} - TZ=Asia/Shanghai volumes: - ${STORAGE_PATH:-./storage}:/data/nex_docus_store diff --git a/forntend/nginx.conf b/forntend/nginx.conf index 7b99d54..809bd9e 100644 --- a/forntend/nginx.conf +++ b/forntend/nginx.conf @@ -12,6 +12,7 @@ server { gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml+rss; # API 反向代理(代理到后端服务) + # 必须在静态资源规则之前,确保 API 请求优先匹配 location /api/ { proxy_pass http://backend:8000/api/; proxy_set_header Host $host; @@ -28,6 +29,10 @@ server { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; + + # 禁用缓存(API 请求不应该被缓存) + proxy_buffering off; + add_header Cache-Control "no-cache, no-store, must-revalidate"; } # 前端路由支持 @@ -36,8 +41,8 @@ server { add_header Cache-Control "no-cache, no-store, must-revalidate"; } - # 静态资源缓存 - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + # 前端静态资源缓存(仅针对前端打包后的静态文件) + location ~* ^/assets/.*\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; }