Where comment attachments are stored. By default Storage.store_file/2
leaves them at the media root; a host can place them next to the
commented record:
config :phoenix_kit_comments, :attachments_parent_folder, {MyApp.Media, :parent_for}called as parent_for(:comment_attachment, actor_uuid, %{resource_type: type, resource_uuid: uuid})
(or parent_for(:comment_attachment, actor_uuid)), returning {:ok, folder_uuid} or nil.
The component asks once per comment and places every file of that comment
with the answer. The hook contract and the placing rule are core's
PhoenixKit.Modules.Storage.ResourceFolders, so nothing here raises or
exits into the caller: it runs inside consume_uploaded_entries/3, after
the files are already stored, so a crash would lose the comment and keep
its uploads.
Summary
Functions
Asks the host hook where attachments for resource_type/resource_uuid
should live. nil (no config, no clause, a nil or non-uuid answer, or
the hook raising, throwing or exiting) means "leave it at the media root"
— the default behaviour.
Puts a just-stored file into folder_uuid (an answer from
parent_folder_uuid/3) by core's attach rule: a homeless file is adopted,
a file homed elsewhere gains a folder link. nil is a no-op, and so is a
folder deleted or trashed since the host answered. Always :ok; a failure
is logged and the file stays where storage put it.
place_file/2 with the folder asked from the hook for this one file.
Functions
Asks the host hook where attachments for resource_type/resource_uuid
should live. nil (no config, no clause, a nil or non-uuid answer, or
the hook raising, throwing or exiting) means "leave it at the media root"
— the default behaviour.
@spec place_file( PhoenixKit.Modules.Storage.File.t() | %{uuid: String.t()}, String.t() | nil ) :: :ok
Puts a just-stored file into folder_uuid (an answer from
parent_folder_uuid/3) by core's attach rule: a homeless file is adopted,
a file homed elsewhere gains a folder link. nil is a no-op, and so is a
folder deleted or trashed since the host answered. Always :ok; a failure
is logged and the file stays where storage put it.
Storage de-duplicates an upload by its bytes, so the file can be one the
uploader trashed: it is wanted again, so it is restored into folder_uuid
rather than left trashed under a new comment. Restore and attach are one
transaction (core's ResourceFolders.place_stored/2), so a folder the
host answered that is gone or trashed by now cannot leave the file active
in a dead home; it comes back live at the media root instead. Restored
by someone else first, it keeps the home they gave it and is attached
here like any other duplicate.
@spec place_stored_file( PhoenixKit.Modules.Storage.File.t() | %{uuid: String.t()}, String.t(), String.t(), String.t() | nil ) :: :ok
place_file/2 with the folder asked from the hook for this one file.