Skip to main content

Module assets

Module assets 

Source
Expand description

Image asset storage for the vault.

Images live as real files under <vault>/assets/<blake3hex16>.<ext>, keyed by a content hash of their bytes so identical images dedup automatically. Memos reference them with the app-relative oximg://<name> scheme, which the Tauri shell resolves to the file (and browser-dev mode resolves to an IndexedDB blob) — see the frontend lib/assets.ts.

Only the file store is touched (no index, no lock): assets are content addressed, so concurrent writers that produce the same bytes collide on the same filename harmlessly, and a partial write is simply overwritten.

Structs§

AssetInfo
One row of the gallery: a discoverable asset plus its size and mtime.
AssetRef
A reference returned to the frontend after saving an image. url is the exact string to drop into markdown (oximg://<name>); name is the bare <hash>.<ext> used by the gallery and GC.

Constants§

ALLOWED_EXTS
Extensions the WKWebView can render inline. HEIC/RAW are excluded on purpose; convert upstream (or add a converter) before widening this set.
HASH_LEN
File-name stem length for a content-hashed asset (first 16 hex chars of a blake3 digest). 16 hex = 64 bits — ample collision resistance for a single user’s image library, and short enough to stay readable in raw markdown.

Functions§

asset_name
Content-hash raw image bytes to a bare asset name (<hex16>.<ext>).
ext_of
The extension portion of a validated asset name (without the dot), or None if the name is malformed.
mime_for_ext
Content-Type for a whitelisted extension.
normalize_ext
Normalize an extension to lowercase ASCII without a leading dot, or reject anything outside the whitelist.
refs_in_body
Extract every oximg://<name> reference from a memo body. Used by the GC to decide which assets are still live. OXIMG_RE is deliberately permissive on the markdown wrapper (![alt](…), bare URL, or ](…)-less fragments) so a reference survives even if a user hand-edits the alt text.
valid_name
Strict validator for a served asset name. Permits only <hex16>.<allowed> — no path separators, no .., no query/fragment. The protocol handler and the GC both gate on this.