🔀 合并测试环境性能优化到生产分支
Build and push Docker image / buildx (push) Has been cancelled
Deploy VitePress site to Pages / build (push) Has been cancelled
Deploy VitePress site to Pages / Deploy (push) Has been cancelled

从已验证并已推送的 test/custom-admin-ui 分支合并静态资源压缩和统一主题资源路由改动。

- 保留生产 Dockerfile 使用前端 main 分支
- 不带入测试环境专用构建配置
- 测试环境已通过 48 组响应式与明暗模式回归
This commit is contained in:
Orion
2026-07-21 17:33:11 +08:00
+7 -1
View File
@@ -10,6 +10,7 @@ from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, HTMLResponse, PlainTextResponse
from starlette.middleware.gzip import GZipMiddleware
from tortoise import Tortoise
from tortoise.contrib.fastapi import register_tortoise
@@ -120,6 +121,8 @@ async def migrate_password_to_hash():
app = FastAPI(lifespan=lifespan)
app.add_middleware(GZipMiddleware, minimum_size=1024, compresslevel=6)
@app.middleware("http")
async def refresh_settings_middleware(request, call_next):
await refresh_settings()
@@ -151,8 +154,11 @@ app.include_router(admin_api)
@app.get("/theme-assets/{asset_path:path}")
@app.get("/assets/{asset_path:path}")
async def theme_asset(asset_path: str):
# Vite with base=/theme-assets/ emits /theme-assets/assets/<file> while
# legacy themes use /theme-assets/<file>. Keep both forms compatible.
normalized_asset_path = asset_path.removeprefix("assets/")
theme_assets = (BASE_DIR / settings.themesSelect / "assets").resolve()
target = (theme_assets / asset_path).resolve()
target = (theme_assets / normalized_asset_path).resolve()
try:
target.relative_to(theme_assets)
except ValueError: