podbox_ash/lib/podbox/podcast/changes/create_enclosure_change.ex

20 lines
528 B
Elixir

defmodule Podbox.Podcast.CreateEnclosureChange do
@moduledoc """
Does a small amount of wrangling needed to create an asset when an enclosure
is created.
"""
use Ash.Resource.Change
alias Ash.Changeset
@doc false
@impl true
def change(changeset, _context, _opts) do
url = Changeset.get_attribute(changeset, :url)
changeset
|> Changeset.manage_relationship(:assets, %{uri: url, asset_type: :enclosure, headers: %{}},
on_no_match: {:create, :enqueue},
on_match: :ignore
)
end
end