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