Fix linting
This commit is contained in:
@@ -479,24 +479,30 @@ def create_app(args):
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
# Custom StaticFiles class for smart caching
|
||||
class SmartStaticFiles(StaticFiles): # Renamed from NoCacheStaticFiles
|
||||
class SmartStaticFiles(StaticFiles): # Renamed from NoCacheStaticFiles
|
||||
async def get_response(self, path: str, scope):
|
||||
response = await super().get_response(path, scope)
|
||||
|
||||
|
||||
if path.endswith(".html"):
|
||||
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
|
||||
response.headers["Cache-Control"] = (
|
||||
"no-cache, no-store, must-revalidate"
|
||||
)
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
response.headers["Expires"] = "0"
|
||||
elif "/assets/" in path: # Assets (JS, CSS, images, fonts) generated by Vite with hash in filename
|
||||
response.headers["Cache-Control"] = "public, max-age=31536000, immutable"
|
||||
elif (
|
||||
"/assets/" in path
|
||||
): # Assets (JS, CSS, images, fonts) generated by Vite with hash in filename
|
||||
response.headers["Cache-Control"] = (
|
||||
"public, max-age=31536000, immutable"
|
||||
)
|
||||
# Add other rules here if needed for non-HTML, non-asset files
|
||||
|
||||
|
||||
# Ensure correct Content-Type
|
||||
if path.endswith(".js"):
|
||||
response.headers["Content-Type"] = "application/javascript"
|
||||
elif path.endswith(".css"):
|
||||
response.headers["Content-Type"] = "text/css"
|
||||
|
||||
|
||||
return response
|
||||
|
||||
# Webui mount webui/index.html
|
||||
@@ -504,7 +510,9 @@ def create_app(args):
|
||||
static_dir.mkdir(exist_ok=True)
|
||||
app.mount(
|
||||
"/webui",
|
||||
SmartStaticFiles(directory=static_dir, html=True, check_dir=True), # Use SmartStaticFiles
|
||||
SmartStaticFiles(
|
||||
directory=static_dir, html=True, check_dir=True
|
||||
), # Use SmartStaticFiles
|
||||
name="webui",
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user