Media utilities: cache, validate, deliver images/audio/video/documents #633
Notifications
Due Date
No due date set.
Depends on
Reference: sam/archie#633
Reference in new issue
Block a user
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
MessageEventor 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-49b39c78BasePlatformAdapter optional methods) but there is no formalbd depbetween 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