Serve bundled branding assets by default
This commit is contained in:
@@ -14,6 +14,7 @@ _FAVICON_PATH = os.path.join(_BRANDING_DIR, "favicon.ico")
|
||||
_BUNDLED_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "assets", "branding"))
|
||||
_BUNDLED_LOGO_PATH = os.path.join(_BUNDLED_DIR, "logo.png")
|
||||
_BUNDLED_FAVICON_PATH = os.path.join(_BUNDLED_DIR, "favicon.ico")
|
||||
_BRANDING_SOURCE = os.getenv("BRANDING_SOURCE", "bundled").lower()
|
||||
|
||||
|
||||
def _ensure_branding_dir() -> None:
|
||||
@@ -80,24 +81,32 @@ def _ensure_default_branding() -> None:
|
||||
favicon.save(_FAVICON_PATH, format="ICO")
|
||||
|
||||
|
||||
def _resolve_branding_paths() -> tuple[str, str]:
|
||||
if _BRANDING_SOURCE == "data":
|
||||
_ensure_default_branding()
|
||||
return _LOGO_PATH, _FAVICON_PATH
|
||||
if os.path.exists(_BUNDLED_LOGO_PATH) and os.path.exists(_BUNDLED_FAVICON_PATH):
|
||||
return _BUNDLED_LOGO_PATH, _BUNDLED_FAVICON_PATH
|
||||
_ensure_default_branding()
|
||||
return _LOGO_PATH, _FAVICON_PATH
|
||||
|
||||
|
||||
@router.get("/logo.png")
|
||||
async def branding_logo() -> FileResponse:
|
||||
if not os.path.exists(_LOGO_PATH):
|
||||
_ensure_default_branding()
|
||||
if not os.path.exists(_LOGO_PATH):
|
||||
logo_path, _ = _resolve_branding_paths()
|
||||
if not os.path.exists(logo_path):
|
||||
raise HTTPException(status_code=404, detail="Logo not found")
|
||||
headers = {"Cache-Control": "public, max-age=300"}
|
||||
return FileResponse(_LOGO_PATH, media_type="image/png", headers=headers)
|
||||
headers = {"Cache-Control": "no-store"}
|
||||
return FileResponse(logo_path, media_type="image/png", headers=headers)
|
||||
|
||||
|
||||
@router.get("/favicon.ico")
|
||||
async def branding_favicon() -> FileResponse:
|
||||
if not os.path.exists(_FAVICON_PATH):
|
||||
_ensure_default_branding()
|
||||
if not os.path.exists(_FAVICON_PATH):
|
||||
_, favicon_path = _resolve_branding_paths()
|
||||
if not os.path.exists(favicon_path):
|
||||
raise HTTPException(status_code=404, detail="Favicon not found")
|
||||
headers = {"Cache-Control": "public, max-age=300"}
|
||||
return FileResponse(_FAVICON_PATH, media_type="image/x-icon", headers=headers)
|
||||
headers = {"Cache-Control": "no-store"}
|
||||
return FileResponse(favicon_path, media_type="image/x-icon", headers=headers)
|
||||
|
||||
|
||||
async def save_branding_image(file: UploadFile) -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user