diff --git a/lib/changelog/schema/episode/episode.ex b/lib/changelog/schema/episode/episode.ex index 756b5ef4eb..4df86f6a97 100644 --- a/lib/changelog/schema/episode/episode.ex +++ b/lib/changelog/schema/episode/episode.ex @@ -227,6 +227,8 @@ defmodule Changelog.Episode do |> validate_format(:socialize_url, Regexp.http(), message: Regexp.http_message()) |> validate_published_has_published_at() |> validate_all_email_fields_together() + |> validate_audio_file_no_plusplus() + |> validate_plusplus_file_yes_plusplus() |> unique_constraint(:slug, name: :episodes_slug_podcast_id_index) |> cast_assoc(:episode_hosts) |> cast_assoc(:episode_guests) @@ -537,4 +539,24 @@ defmodule Changelog.Episode do changeset end end + + defp validate_audio_file_no_plusplus(changeset) do + audio_file = get_field(changeset, :audio_file) + + if audio_file && String.contains?(audio_file.file_name, "++") do + add_error(changeset, :audio_file, "this looks like a ++ mp3 (filename)") + else + changeset + end + end + + defp validate_plusplus_file_yes_plusplus(changeset) do + plusplus_file = get_field(changeset, :plusplus_file) + + if plusplus_file && !String.contains?(plusplus_file.file_name, "++") do + add_error(changeset, :plusplus_file, "this doesn't look like a ++ mp3 (filename)") + else + changeset + end + end end diff --git a/lib/changelog_web/templates/admin/episode/_form.html.heex b/lib/changelog_web/templates/admin/episode/_form.html.heex index 6848e4bc00..77e484ce5a 100644 --- a/lib/changelog_web/templates/admin/episode/_form.html.heex +++ b/lib/changelog_web/templates/admin/episode/_form.html.heex @@ -307,6 +307,7 @@ <% end %> <%= file_input(f, :audio_file) %> + <%= AdminHelpers.error_message(f, :audio_file) %> <% has_audio_chapters = Enum.any?(f.data.audio_chapters) %> @@ -422,6 +423,7 @@ <% end %> <%= file_input(f, :plusplus_file) %> + <%= AdminHelpers.error_message(f, :plusplus_file) %> <% has_plusplus_chapters = Enum.any?(f.data.plusplus_chapters) %>