fix: filter public media roles by entity
This commit is contained in:
@@ -6,6 +6,21 @@ from pathlib import Path
|
||||
|
||||
|
||||
MEDIA_ROOT = Path(os.environ.get("MEDIA_ROOT", "data/media")).resolve()
|
||||
WATERBODY_MEDIA_ROLES = {"waterbody_cover", "waterbody_map", "waterbody_depth_map", "waterbody_screenshot"}
|
||||
TACKLE_MEDIA_ROLES = {"tackle_card", "tackle_detail", "rig_diagram", "tackle_screenshot"}
|
||||
KNOWN_MEDIA_ROLES = WATERBODY_MEDIA_ROLES | TACKLE_MEDIA_ROLES
|
||||
|
||||
|
||||
def _public_role_allowed(entity_type: str | None, role: object) -> bool:
|
||||
if role is None:
|
||||
return True
|
||||
if not isinstance(role, str) or role not in KNOWN_MEDIA_ROLES:
|
||||
return False
|
||||
if entity_type == "waterbody":
|
||||
return role in WATERBODY_MEDIA_ROLES
|
||||
if entity_type == "tackle":
|
||||
return role in TACKLE_MEDIA_ROLES
|
||||
return False
|
||||
|
||||
|
||||
def published_assets(entity_type: str | None = None) -> list[dict]:
|
||||
@@ -16,6 +31,8 @@ def published_assets(entity_type: str | None = None) -> list[dict]:
|
||||
continue
|
||||
if entity_type and item.get("entity_type") != entity_type:
|
||||
continue
|
||||
if not _public_role_allowed(item.get("entity_type"), item.get("media_role")):
|
||||
continue
|
||||
source_page = str(item.get("source_page") or "")
|
||||
source = "rf4db" if "rf4db.com" in source_page else "rf4map" if "rf4map.ru" in source_page else "rf4-official"
|
||||
result.append({
|
||||
|
||||
Reference in New Issue
Block a user