Updated View as Markdown

Media uploads

Media uploads

Uploads local files that Markdown pages reference (![x](img/a.png), [spec](file.pdf)) to Storefront’s media library (POST /api/media) and rewrites the reference to the returned public URL. A file is validated (exists, inside the repo, allowed extension, under the size cap) before it is uploaded; a file’s content is hashed so the same bytes referenced under two different paths upload once.

PendingUpload

pub struct PendingUpload { resolved_path : String, abs_path : PathBuf, file : String, line : usize, }

One distinct local file to upload: the first reference to this path, kept for error messages, and the absolute path to read its bytes from.

plan_uploads

pub fn plan_uploads(root : & Path, refs : & [MediaReference]) ->(Vec < PendingUpload >, Vec < MediaError >);

Validates every media reference against the repo at root and returns the distinct files that pass, deduplicated by their resolved repo path (so a file referenced twice is uploaded once). Every reference that fails validation, or climbs above the repo root, is an error naming the Markdown file, line and cause; a repeat reference to an already-failed path is not re-validated.

library_path

pub fn library_path(base_path : & str) -> String;

The media library folder uploads are placed in, derived from base_path so assets pushed from different sources do not collide. The library root (base_path of /) uploads with no path field.

upload_all

pub async fn upload_all(client : & StorefrontClient, library_path : & str, pending : Vec < PendingUpload >,) -> Result < HashMap < String, String >, MediaError >;

Uploads every pending file (POST /api/media) and returns the map from its resolved repo path to the URL Storefront answered. Two files with identical content upload once: the second reference reuses the first upload’s URL by content hash. Stops at the first upload failure (a 4xx or 5xx from Storefront): uploads are never skipped silently.

upload_diagrams

pub async fn upload_diagrams(client : & StorefrontClient, library_path : & str, pending : Vec < RenderedDiagram >,) -> Result < HashMap < String, String >, MediaError >;

Uploads every rendered diagram and returns the map from its resolved repo path to the URL Storefront answered, deduped by content hash the same way upload_all dedupes ordinary media.

Back to top