Skip to main content

Module media

Module media 

Source
Expand description

Media repository for attachments. Blobs are opaque bytes: in E2E rooms clients upload AES-CTR ciphertext (Matrix encrypted attachments), so the server stores ciphertext only. They follow the ciphertext-pump rule: kept for a TTL (see purge_expired) and then deleted. Plaintext uploads for public channels use the same table and the same TTL for now; a separate persistent public-media store is a named seam, not built.

Structs§

Blob
A fetched blob.

Enums§

Part
What the second part of a federation media answer holds.

Constants§

MAX_UPLOAD_BYTES
Default largest accepted upload (and largest remote file fetched). Env: M4A_MEDIA_MAX_BYTES.

Functions§

create_media_schema
DDL (own table, outside the event tables).
create_pending
Reserves a media id for a later PUT (POST /media/v1/create).
federation_enabled
Is media federation (serving peers, fetching remote media) on? Cargo feature media-federation (default) and M4A_MEDIA_FEDERATION not off.
get
Fetches a blob.
get_remote
A cached copy of another server’s file, if still fresh.
is_pending
Is a reservation open (the id was handed out and not yet filled)?
max_bytes
Largest upload / remote file in bytes (M4A_MEDIA_MAX_BYTES).
multipart_body
multipart/mixed answer of the federation media endpoints: a JSON part {}, then the file.
parse_multipart
Parses a multipart/mixed federation media answer (JSON part, then data or Location).
purge_expired
Deletes blobs older than ttl_ms. Returns how many.
put
Stores a blob and returns its media id (24 url-safe chars).
put_remote
Caches another server’s file; drops expired copies, then the oldest while over the cap.
put_reserved
Fills a reserved id. Ok(false): not reserved by this user (or expired); Err(Constraint) if filled already.
remote_cache_cap
Cap on all cached remote bytes (M4A_MEDIA_REMOTE_CACHE_BYTES, default 512 MiB); oldest go first.
remote_ttl_ms
How long a cached remote file is kept, ms (M4A_MEDIA_REMOTE_TTL_SECS, default 7 days).
thumbnail
A thumbnail of an image, or None when it is not a decodable image (ciphertext, other files) or the feature is off; callers then serve the original. Never enlarges.