From 7bba4313bd65bffd4cbef9c626a67bf220b5dc5d Mon Sep 17 00:00:00 2001 From: Orion Date: Fri, 5 Jun 2026 17:47:56 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E9=81=BF=E5=85=8D=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E8=B5=84=E6=BA=90=E5=91=BD=E4=B8=AD=E6=97=A7=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index c8698aa..67fc1b1 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ # @File : main.py # @Software: PyCharm import asyncio +import re import time from contextlib import asynccontextmanager @@ -147,6 +148,7 @@ app.include_router(presign_api, prefix="/api") 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): theme_assets = (BASE_DIR / settings.themesSelect / "assets").resolve() @@ -166,17 +168,26 @@ async def theme_asset(asset_path: str): @app.exception_handler(404) @app.get("/") async def index(request=None, exc=None): - return HTMLResponse( - content=open( - BASE_DIR / f"{settings.themesSelect}/index.html", "r", encoding="utf-8" - ) + theme_dir = BASE_DIR / settings.themesSelect + asset_version = str(int((theme_dir / "index.html").stat().st_mtime)) + content = ( + open(theme_dir / "index.html", "r", encoding="utf-8") .read() .replace("{{title}}", str(settings.name)) .replace("{{description}}", str(settings.description)) .replace("{{keywords}}", str(settings.keywords)) .replace("{{opacity}}", str(settings.opacity)) - .replace('"/assets/', '"assets/') - .replace("{{background}}", str(settings.background)), + .replace('"/assets/', '"/theme-assets/') + .replace('"assets/', '"/theme-assets/') + .replace("{{background}}", str(settings.background)) + ) + content = re.sub( + r'((?:theme-)?assets/[^"\']+\.(?:css|js|json|png))(["\'])', + rf"\1?v={asset_version}\2", + content, + ) + return HTMLResponse( + content=content, media_type="text/html", headers={"Cache-Control": "no-cache"}, )