Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gateway/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,12 +829,20 @@ def cache_video_from_bytes(data: bytes, ext: str = ".mp4") -> str:
MEDIA_DELIVERY_ALLOW_DIRS_ENV = "HERMES_MEDIA_ALLOW_DIRS"
MEDIA_DELIVERY_TRUST_RECENT_ENV = "HERMES_MEDIA_TRUST_RECENT_FILES"
MEDIA_DELIVERY_TRUST_RECENT_SECONDS_ENV = "HERMES_MEDIA_TRUST_RECENT_SECONDS"
_MEDIA_DELIVERY_CANONICAL_CACHE_ROOTS = (
_HERMES_HOME / "cache" / "images",
_HERMES_HOME / "cache" / "audio",
_HERMES_HOME / "cache" / "videos",
_HERMES_HOME / "cache" / "documents",
_HERMES_HOME / "cache" / "screenshots",
)
MEDIA_DELIVERY_SAFE_ROOTS = (
IMAGE_CACHE_DIR,
AUDIO_CACHE_DIR,
VIDEO_CACHE_DIR,
DOCUMENT_CACHE_DIR,
SCREENSHOT_CACHE_DIR,
*_MEDIA_DELIVERY_CANONICAL_CACHE_ROOTS,
_HERMES_HOME / "image_cache",
_HERMES_HOME / "audio_cache",
_HERMES_HOME / "video_cache",
Expand Down
10 changes: 10 additions & 0 deletions tests/gateway/test_platform_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from gateway.platforms.base import (
BasePlatformAdapter,
GATEWAY_SECRET_CAPTURE_UNSUPPORTED_MESSAGE,
MEDIA_DELIVERY_SAFE_ROOTS,
MessageEvent,
MessageType,
safe_url_for_log,
Expand Down Expand Up @@ -535,6 +536,15 @@ def test_filter_keeps_recently_produced_files(self, tmp_path, monkeypatch):
out = BasePlatformAdapter.filter_local_delivery_paths([str(fresh)])
assert out == [str(fresh.resolve())]

def test_default_roots_include_canonical_media_caches(self):
suffixes = {tuple(root.parts[-2:]) for root in MEDIA_DELIVERY_SAFE_ROOTS}

assert ("cache", "images") in suffixes
assert ("cache", "audio") in suffixes
assert ("cache", "videos") in suffixes
assert ("cache", "documents") in suffixes
assert ("cache", "screenshots") in suffixes


# ---------------------------------------------------------------------------
# should_send_media_as_audio
Expand Down