PhoenixKitAgent.Library (PhoenixKitAgent v0.1.0)

Copy Markdown View Source

The module's own Storage library, where attachment bytes are kept.

It is a hidden system library (Libraries.create_system_library/2 with hidden: true): the site does not list it, not in Media's switcher nor in the media pickers, its files get only expiring URLs, and media.view_all opens none of them — only their uploader and an Owner/Admin may read one (an Owner/Admin reads any file of Storage by design). It is found again by its fixed slug and created on first use.

Inside it every user has a folder named by their user_uuid, at the library root, created on demand. The folder only keeps things in order: Storage rights are per file, the protection is the hidden library and the module being the only way to the bytes.

Summary

Functions

The module's library, created when it does not exist yet. Two callers racing to create it both get the one library. {:error, changeset} when the slug or the name is taken by a library the module did not create.

The user's folder in the module's library, created (with the library) when it does not exist yet.

The module's library, or nil while it has not been created.

The fixed slug the module finds its library by.

The user's folder in the module's library, or nil while there is none.

Functions

ensure_library()

@spec ensure_library() ::
  {:ok, PhoenixKit.Modules.Storage.Library.t()} | {:error, Ecto.Changeset.t()}

The module's library, created when it does not exist yet. Two callers racing to create it both get the one library. {:error, changeset} when the slug or the name is taken by a library the module did not create.

ensure_user_folder(user_uuid)

@spec ensure_user_folder(String.t()) ::
  {:ok, PhoenixKit.Modules.Storage.Folder.t()}
  | {:error, :invalid_user_uuid | Ecto.Changeset.t()}

The user's folder in the module's library, created (with the library) when it does not exist yet.

library()

@spec library() :: PhoenixKit.Modules.Storage.Library.t() | nil

The module's library, or nil while it has not been created.

slug()

@spec slug() :: String.t()

The fixed slug the module finds its library by.

user_folder(user_uuid)

@spec user_folder(String.t()) :: PhoenixKit.Modules.Storage.Folder.t() | nil

The user's folder in the module's library, or nil while there is none.