Media utilities: cache, validate, deliver images/audio/video/documents #633

Closed
opened 2026-10-27 13:37:07 +00:00 by sam · 0 comments
Owner

Shared media utilities for handling images/audio/video/documents across platform adapters: download from the platform, validate (MIME type, size ceiling), cache to avoid re-fetching, and hand back a normalized reference the gateway can attach to a MessageEvent or deliver outbound.

Context for implementers

No media file exists yet in internal/gateway. MessageEvent (internal/gateway/messageevent.go) is the shared event model this should plug into — check its current field set before adding a parallel media type. This is infrastructure other Gateway epic items depend on conceptually (any adapter method that sends/receives media, e.g. archie-core-1786637493329-136-49b39c78 BasePlatformAdapter optional methods) but there is no formal bd dep between them yet.

Acceptance Criteria

A shared utility validates MIME type and size before accepting media, caches downloaded media keyed by platform + media ID with TTL/size-bounded eviction, and exposes a normalized reference type usable from any adapter. Oversized or disallowed-MIME media is rejected with a caller-visible error, not silently dropped.

Notes

Most of this landed separately over the last two months: the shared vocabulary is internal/domain/messaging/media.go (MediaAttachment, MediaType*, MaxInboundAttachmentBytes) and MediaSender, and the size ceiling with a caller-visible error is in the Telegram download path (channels/telegram/inboundmedia.go:114-152). What was missing is the MIME check: both acceptance points (webui/api_chat.go voice upload, Telegram fetchTurnMedia) trusted the declared content type, so a file could be used as something it was not -- transcribed as a voice note, or sent to a model as an image. messaging.ValidateInbound now refuses an unknown type, content over the ceiling, and a MIME type contradicting the type, with the error the caller sees. The cache is not built: bytes are used once per turn for transcription or vision and stored history is text-only, so nothing would read from it; drop that clause unless a second reader appears.

Close reason

Delivered as the missing half: shared vocabulary and size ceiling already existed, MIME validation added at both acceptance points (14779245). Cache dropped: no reader for it. MediaSender/MaxInboundAttachmentBytes remain the adapter contract.


Imported from beads archie-core-1786637492590-107-92482ef1 · GitHub #128 · type task · priority P2 · created 2026-08-08 · closed 2026-10-25

Shared media utilities for handling images/audio/video/documents across platform adapters: download from the platform, validate (MIME type, size ceiling), cache to avoid re-fetching, and hand back a normalized reference the gateway can attach to a `MessageEvent` or deliver outbound. ### Context for implementers No media file exists yet in `internal/gateway`. `MessageEvent` (`internal/gateway/messageevent.go`) is the shared event model this should plug into — check its current field set before adding a parallel media type. This is infrastructure other Gateway epic items depend on conceptually (any adapter method that sends/receives media, e.g. `archie-core-1786637493329-136-49b39c78` BasePlatformAdapter optional methods) but there is no formal `bd dep` between them yet. ### Acceptance Criteria A shared utility validates MIME type and size before accepting media, caches downloaded media keyed by platform + media ID with TTL/size-bounded eviction, and exposes a normalized reference type usable from any adapter. Oversized or disallowed-MIME media is rejected with a caller-visible error, not silently dropped. ### Notes Most of this landed separately over the last two months: the shared vocabulary is internal/domain/messaging/media.go (MediaAttachment, MediaType*, MaxInboundAttachmentBytes) and MediaSender, and the size ceiling with a caller-visible error is in the Telegram download path (channels/telegram/inboundmedia.go:114-152). What was missing is the MIME check: both acceptance points (webui/api_chat.go voice upload, Telegram fetchTurnMedia) trusted the declared content type, so a file could be used as something it was not -- transcribed as a voice note, or sent to a model as an image. messaging.ValidateInbound now refuses an unknown type, content over the ceiling, and a MIME type contradicting the type, with the error the caller sees. The cache is not built: bytes are used once per turn for transcription or vision and stored history is text-only, so nothing would read from it; drop that clause unless a second reader appears. ### Close reason Delivered as the missing half: shared vocabulary and size ceiling already existed, MIME validation added at both acceptance points (14779245). Cache dropped: no reader for it. MediaSender/MaxInboundAttachmentBytes remain the adapter contract. --- _Imported from beads `archie-core-1786637492590-107-92482ef1` · GitHub #128 · type task · priority P2 · created 2026-08-08 · closed 2026-10-25_
sam added the mediumtask labels 2026-10-27 13:37:07 +00:00
sam self-assigned this 2026-10-27 13:37:07 +00:00
sam closed this issue 2026-10-27 13:37:07 +00:00
sam added a new dependency 2026-10-27 13:42:09 +00:00
sam added the feature label 2026-11-14 14:45:20 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sam/archie#633