Skip to main content

Module media

Module media 

Expand description

Inbound media attachments and the three questions callers ask about them.

An attachment carries several signals — a sender-declared MIME, a file name, and the payload itself — and they can disagree. Rather than force one verdict on every caller, this module exposes three deliberately different answers, each matched to what its consumer does with it:

  • MediaAttachment::kind — routing. Resolves one kind, declared MIME first, so an attachment is processed as whatever the sender said it is.
  • MediaAttachment::looks_like_image — restriction. True when any signal says image, so a contradictory MIME cannot smuggle a photo past an image-turn gate. Over-applies rather than under-applies, because its consumers only remove capability.
  • MediaAttachment::provider_loadable_image_mime — grant. Some only when the multimodal loader will actually accept the bytes, so nothing promises the provider an image it will drop.

The three are ordered by strictness (provider_loadable_image_mime implies looks_like_image), but kind is independent and may disagree with both. Callers that render user-visible annotations must therefore not let two of these decide the same attachment: the channel that received the bytes records what it rendered in MediaAttachment::marker, and later stages defer to that instead of re-deciding.

Structs§

MediaAttachment
A single media attachment on an inbound message.
RenderedMarker
The marker a receiving channel rendered into the message text for an attachment’s exact bytes: the target it referenced and the disposition it chose.

Enums§

MarkerKind
The disposition a receiving channel chose when it rendered an attachment’s marker into the message text.
MediaKind
Classifies an attachment by MIME type or file extension.

Constants§

PROVIDER_IMAGE_MIME_TYPES
Image MIME types the multimodal provider path accepts.

Functions§

image_mime_from_extension
Map a bare file extension to the image MIME the multimodal loader assigns it. Returns Some for formats the loader recognizes, which is a wider set than it accepts — bmp resolves here so the loader can reject it by name instead of failing as an unknown format.
image_mime_from_magic
Map leading magic bytes to the image MIME the multimodal loader assigns them. Recognizes the same wider-than-accepted set as image_mime_from_extension.
is_provider_image_mime
Whether mime is one the multimodal provider path accepts.
provider_loadable_image_mime_for
The provider-loadable image MIME for a (file_name, bytes) pair, or None when the loader would reject it. Free-standing so a channel can consult the same contract before it owns a MediaAttachment: Discord decides a marker’s disposition from the borrowed download bytes, and duplicating the precedence here would let the two drift. MediaAttachment::provider_loadable_image_mime is the borrowing convenience over this.