feat: filter public media by role
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
from ..media_catalog import published_assets, published_file
|
||||
from ..media_catalog import KNOWN_MEDIA_ROLES, published_assets, published_file
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/api/v1/media/catalog")
|
||||
def media_catalog(entity_type: str | None = Query(None, pattern="^(fish|waterbody|tackle|reference)$")) -> list[dict]:
|
||||
return published_assets(entity_type)
|
||||
def media_catalog(
|
||||
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]:
|
||||
if media_role and entity_type not in {"waterbody", "tackle"}:
|
||||
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")
|
||||
return published_assets(entity_type, media_role)
|
||||
|
||||
|
||||
@router.get("/api/v1/media/assets/{digest}", response_class=FileResponse)
|
||||
|
||||
Reference in New Issue
Block a user