Reference to a source image. Produced by a provider, consumed by a source resolver.
A source is intentionally a thin tagged reference. The provider names what the source is (an absolute path, an absolute URL, or a hosted asset id) and the source resolver decides where the bytes come from.
Sources never hold image bytes themselves.
Summary
Types
The kind of source. Determines which Image.Plug.SourceResolver
implementation handles it.
Types
@type kind() :: :path | :url | :hosted
The kind of source. Determines which Image.Plug.SourceResolver
implementation handles it.
:path—refis an absolute path string. Resolved against a configured root directory byImage.Plug.SourceResolver.File.:url—refis an absolutehttp(s)://URL. Resolved byImage.Plug.SourceResolver.HTTPagainst an allow-list.:hosted—refis a{account_hash, image_id}tuple. Resolved byImage.Plug.SourceResolver.Hostedagainst a host-supplied asset table.
Functions
Builds a :hosted source.
Arguments
account_hashis an opaque account identifier string.image_idis an opaque image identifier string.
Returns
- An
Image.Plug.Sourcestruct (always succeeds).
Examples
iex> source = Image.Plug.Source.hosted("acct123", "img456")
iex> source.kind
:hosted
iex> source.ref
{"acct123", "img456"}
@spec path(String.t()) :: {:ok, t()} | {:error, Image.Plug.Error.t()}
Builds a :path source.
Arguments
pathis an absolute path string (must start with/).
Returns
{:ok, source}on success.{:error, %Image.Plug.Error{tag: :invalid_option}}if the path is not absolute or contains..segments.
Examples
iex> {:ok, source} = Image.Plug.Source.path("/foo/bar.jpg")
iex> source.kind
:path
iex> {:error, error} = Image.Plug.Source.path("relative.jpg")
iex> error.tag
:invalid_option
@spec url(String.t()) :: {:ok, t()} | {:error, Image.Plug.Error.t()}
Builds a :url source.
Arguments
urlis an absolutehttp://orhttps://URL.
Returns
{:ok, source}on success.{:error, %Image.Plug.Error{tag: :invalid_option}}if the URL is missing a scheme or host.
Examples
iex> {:ok, source} = Image.Plug.Source.url("https://example.com/a.jpg")
iex> source.kind
:url
iex> {:error, error} = Image.Plug.Source.url("not-a-url")
iex> error.tag
:invalid_option