PhoenixKit.Modules.Storage.FileReport (phoenix_kit v2.60.2)

Copy Markdown View Source

What is stored for one file, and whether it is all there: the data behind a file's storage page.

renditions/1 lists the original and every size the file's variant set wants (VariantGenerator.expected_variants/1), then whatever else the file carries (a burned-annotation copy), each with its state and the buckets that hold it. The states follow the reconciler's own reading (Reconciler.reconcile_file/1 makes what is :missing or :stale):

  • :ok — stored, made from the size's current spec
  • :missing — the set wants it and the file has no instance of it
  • :stale — made from another spec than the size has now
  • :processing / :failed — its instance row says so
  • :no_copy — an instance whose object no bucket is recorded to hold

verify/1 reads every copy back from its own bucket and compares the SHA-256 with the one recorded when the object was stored. Slow on a large file or a cloud bucket: call it from a task, not a render.

Summary

Types

One bucket's copy of an object.

Functions

Whether every result of verify/1 is :ok.

How many renditions are still wrong after a repair: those a verification found failing, and those the file lacks or has made from another spec (the original among them), counted once each. reconciled?: false (the reconciler could not finish) counts as one when nothing else shows.

Whether the file has anything to put right: a rendition missing, made from an older spec, or an object no bucket holds.

The rows of file: the original, the sizes its set wants, then the rest.

Reads every copy of every instance back from its own bucket and compares it with the checksum recorded for it.

Types

copy()

@type copy() :: %{
  bucket: PhoenixKit.Modules.Storage.Bucket.t(),
  status: String.t(),
  path: String.t(),
  last_verified_at: DateTime.t() | nil
}

One bucket's copy of an object.

row()

@type row() :: %{
  name: String.t(),
  kind: :original | :size | :alternative | :annotated | :other,
  state: state(),
  instance: PhoenixKit.Modules.Storage.FileInstance.t() | nil,
  dimension: struct() | nil,
  format: String.t() | nil,
  copies: [copy()]
}

state()

@type state() :: :ok | :missing | :stale | :processing | :failed | :no_copy

Functions

all_ok?(results)

@spec all_ok?([map()]) :: boolean()

Whether every result of verify/1 is :ok.

problem_count(file, verification, opts \\ [])

@spec problem_count(PhoenixKit.Modules.Storage.File.t(), [map()], keyword()) ::
  non_neg_integer()

How many renditions are still wrong after a repair: those a verification found failing, and those the file lacks or has made from another spec (the original among them), counted once each. reconciled?: false (the reconciler could not finish) counts as one when nothing else shows.

problems(file)

@spec problems(PhoenixKit.Modules.Storage.File.t() | [row()]) :: [row()]

Whether the file has anything to put right: a rendition missing, made from an older spec, or an object no bucket holds.

renditions(file)

@spec renditions(PhoenixKit.Modules.Storage.File.t()) :: [row()]

The rows of file: the original, the sizes its set wants, then the rest.

verify(file, opts \\ [])

@spec verify(PhoenixKit.Modules.Storage.File.t(), keyword()) :: [map()]

Reads every copy of every instance back from its own bucket and compares it with the checksum recorded for it.

Pass audit: (the audit options, :actor_uuid and :found_by) to record each damaged copy in the Activity log (Audit.log_damage/3).

One result per copy: %{name, bucket, path, result} where result is :ok, {:mismatch, recorded, actual}, :not_found, {:unrecorded, actual} (no checksum was recorded to compare with) or {:error, reason}. An instance with no copy at all gives one result with bucket: nil and :no_copy.