PhoenixKitOG.Render.Media (PhoenixKitOG v0.3.1)

Copy Markdown View Source

Media resolution + render-mode pre-processing between the stored scene and OpenFresco.render/3.

OpenFresco's rasterizer deliberately reads no network: image inputs must be data: URLs (or local files). Everything in this module exists to bridge that:

  • Media UUIDs (from the media picker, or a consumer's og_resolve/2 returning a storage UUID) are resolved to file bytes via core Storage and inlined as data: URLs.
  • file:// is rejected outright — a local-file-read primitive with no legitimate use here.
  • Remote http(s) passes through; the renderer skips it, matching the legacy pipeline's behavior.

Render modes:

  • :preview — unresolved image slots stay unresolved so OpenFresco draws its labeled stand-in (the editor/assignments affordance).
  • :public — a crawler-facing card must never ship a stand-in: an image element whose slot has no value is dropped, and an image background falls back to the house dark solid — the legacy pipeline's exact semantics.

Summary

Functions

Prepares {scene, values} for a render: resolves media UUIDs in both, then applies :public-mode fallbacks for unresolved image slots.

Resolves a single image reference. Returns the renderable value or nil when it can't be used (unresolvable UUID, file://, host-relative path, non-binary).

Resolves image-typed slot values: a value that looks like a media UUID becomes a data: URL; data:/http(s) pass through; file:// and host-relative paths are dropped to nil (unresolved).

OpenFresco resource-resolver fun (the 0.2.0 shared stage/rasterizer contract): media UUIDs resolve to local file bytes; anything else is :skip so OpenFresco's deny-by-default href policy applies. Used by the editor stage so authors see their picked media instead of a stand-in — the PNG path keeps its own pre-resolution (the cache key must reflect the actual image bytes, since a media UUID's content can change under it, e.g. rotation).

Functions

prepare(scene, values, mode)

@spec prepare(OpenFresco.Scene.t(), map(), :public | :preview) ::
  {OpenFresco.Scene.t(), map()}

Prepares {scene, values} for a render: resolves media UUIDs in both, then applies :public-mode fallbacks for unresolved image slots.

resolve_image_value(url)

@spec resolve_image_value(term()) :: String.t() | nil

Resolves a single image reference. Returns the renderable value or nil when it can't be used (unresolvable UUID, file://, host-relative path, non-binary).

resolve_values(values, slots)

@spec resolve_values(map(), [%{name: String.t(), type: atom()}]) :: map()

Resolves image-typed slot values: a value that looks like a media UUID becomes a data: URL; data:/http(s) pass through; file:// and host-relative paths are dropped to nil (unresolved).

resolver()

@spec resolver() :: (String.t() -> {:ok, map()} | :skip)

OpenFresco resource-resolver fun (the 0.2.0 shared stage/rasterizer contract): media UUIDs resolve to local file bytes; anything else is :skip so OpenFresco's deny-by-default href policy applies. Used by the editor stage so authors see their picked media instead of a stand-in — the PNG path keeps its own pre-resolution (the cache key must reflect the actual image bytes, since a media UUID's content can change under it, e.g. rotation).