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.Someonly 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§
- Media
Attachment - A single media attachment on an inbound message.
- Rendered
Marker - 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§
- Marker
Kind - The disposition a receiving channel chose when it rendered an attachment’s marker into the message text.
- Media
Kind - 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
Somefor formats the loader recognizes, which is a wider set than it accepts —bmpresolves 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
mimeis one the multimodal provider path accepts. - provider_
loadable_ image_ mime_ for - The provider-loadable image MIME for a
(file_name, bytes)pair, orNonewhen the loader would reject it. Free-standing so a channel can consult the same contract before it owns aMediaAttachment: 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_mimeis the borrowing convenience over this.