perf: cache media manifest revisions
CI / backend-and-migrations (push) Failing after 33s
CI / astro-build (push) Failing after 31s
CI / dependency-audit (push) Failing after 38s
CI / compose-e2e (push) Failing after 42s

This commit is contained in:
ik
2026-09-22 20:11:02 +07:00
parent 4b0973b1ab
commit cd862103b8
4 changed files with 43 additions and 8 deletions
+5 -2
View File
@@ -1,7 +1,7 @@
from fastapi import APIRouter, HTTPException, Query
from fastapi import APIRouter, HTTPException, Query, Response
from fastapi.responses import FileResponse
from ..media_catalog import KNOWN_MEDIA_ROLES, published_assets, published_file
from ..media_catalog import KNOWN_MEDIA_ROLES, media_manifest_version, published_assets, published_file
router = APIRouter()
@@ -9,6 +9,7 @@ router = APIRouter()
@router.get("/api/v1/media/catalog")
def media_catalog(
response: Response,
entity_type: str | None = Query(None, pattern="^(fish|waterbody|tackle|reference)$"),
media_role: str | None = Query(None, pattern="^(waterbody_cover|waterbody_map|waterbody_depth_map|waterbody_screenshot|tackle_card|tackle_detail|rig_diagram|tackle_screenshot)$"),
) -> list[dict]:
@@ -16,6 +17,8 @@ def media_catalog(
raise HTTPException(status_code=422, detail="media_role requires waterbody or tackle entity_type")
if media_role and media_role not in KNOWN_MEDIA_ROLES:
raise HTTPException(status_code=422, detail="unknown media role")
response.headers["Cache-Control"] = "public, max-age=60, stale-while-revalidate=60"
response.headers["X-Media-Manifest-Version"] = str(media_manifest_version())
return published_assets(entity_type, media_role)