Expand description
On-disk storage of saved render image bytes.
Saved renders are stored as files under <storage_dir>/renders/. Each
file is named by the render’s UUID plus a suffix that distinguishes the
primary image from the optional without-route variant. The DB row carries
just the relative filename so the actual storage location can change
without a schema migration.
Constants§
- IMAGE_
SUFFIX - Suffix used for the primary rendered image file.
- IMAGE_
WITHOUT_ ROUTE_ SUFFIX - Suffix used for the optional “without route” variant of a render.
Functions§
- ensure_
layout - Create the on-startup subdirectory layout under
storage_dir. - ext_
for_ content_ type - Map an
image/...MIME type to the file extension that should be used on disk. Returnsbinfor anything unrecognised so the file is still preserved and can be inspected manually. - list_
logo_ files - List the filenames currently present under the
logos/subdirectory. Used by the orphan sweeper. - list_
render_ files - List the filenames currently present under the
renders/subdirectory. Used by the orphan sweeper. - logo_
filename - Compute the relative filename (relative to
<storage_dir>/logos/) for a logo’s image file given the logo id and extension. - logo_
path - Compute the absolute path to a logo file.
- parse_
logo_ id_ from_ filename - Extract the logo UUID prefix from a filename produced by
logo_filename. ReturnsNoneif the filename does not start with a valid 36-character hyphenated UUID. - parse_
render_ id_ from_ filename - Extract the render UUID prefix from a filename produced by
render_filename. ReturnsNoneif the filename does not start with a valid 36-character hyphenated UUID. Filenames are of the form{render_id}-{suffix}.{ext}, whererender_iditself contains four hyphens, so we cannot just split on-. - read_
logo_ file - Read a logo’s image bytes back from disk.
- read_
render_ file - Read the rendered image bytes back from disk.
- render_
filename - Compute the relative filename (relative to
<storage_dir>/renders/) for a render’s image file given the render id, suffix, and extension. - render_
path - Compute the absolute path to a render file.
- try_
delete_ logo_ file - Best-effort delete of a single logo file. A missing file is treated as
success. See
try_delete_render_filefor the rationale. - try_
delete_ render_ file - Best-effort delete of a single render file. A missing file is treated as success (the row may have been deleted already). Other errors are returned so the caller can decide whether to surface them or raise the sweeper “dirty” flag for a later retry.
- write_
logo_ file - Write a logo’s image bytes to disk, returning the filename that should be stored in the DB.
- write_
render_ file - Write the rendered image bytes for a render to disk, returning the filename that should be stored in the DB.