[WIP] added basic codec preference fields to settings form

This commit is contained in:
Kieran Eglin 2024-05-21 13:03:41 -07:00
parent 3cb7c2c70c
commit 14742d442a
No known key found for this signature in database
GPG key ID: 193984967FCF432D
4 changed files with 59 additions and 2 deletions

View file

@ -13,7 +13,9 @@ defmodule Pinchflat.Settings.Setting do
:apprise_version, :apprise_version,
:apprise_server, :apprise_server,
:video_codec_preference, :video_codec_preference,
:audio_codec_preference :audio_codec_preference,
:video_codec_preference_string,
:audio_codec_preference_string
] ]
@required_fields ~w( @required_fields ~w(
@ -38,6 +40,31 @@ defmodule Pinchflat.Settings.Setting do
def changeset(setting, attrs) do def changeset(setting, attrs) do
setting setting
|> cast(attrs, @allowed_fields) |> cast(attrs, @allowed_fields)
|> convert_codec_preference_strings()
|> validate_required(@required_fields) |> validate_required(@required_fields)
end end
# TODO: test
defp convert_codec_preference_strings(changeset) do
fields = [
video_codec_preference_string: :video_codec_preference,
audio_codec_preference_string: :audio_codec_preference
]
Enum.reduce(fields, changeset, fn {virtual_field, actual_field}, changeset ->
case get_change(changeset, virtual_field) do
nil ->
changeset
value ->
new_value =
value
|> String.split(">")
|> Enum.map(&String.trim/1)
|> Enum.reject(&(String.trim(&1) == ""))
put_change(changeset, actual_field, new_value)
end
end)
end
end end

View file

@ -9,7 +9,7 @@
Oops, something went wrong! Please check the errors below. Oops, something went wrong! Please check the errors below.
</.error> </.error>
<h3 class=" text-2xl text-black dark:text-white"> <h3 class="text-2xl text-black dark:text-white">
General Options General Options
</h3> </h3>

View file

@ -12,6 +12,7 @@ defmodule PinchflatWeb.Settings.SettingController do
def update(conn, %{"setting" => setting_params}) do def update(conn, %{"setting" => setting_params}) do
setting = Settings.record() setting = Settings.record()
IO.inspect(setting_params)
case Settings.update_setting(setting, setting_params) do case Settings.update_setting(setting, setting_params) do
{:ok, _} -> {:ok, _} ->

View file

@ -15,5 +15,34 @@
) %> ) %>
</section> </section>
<section class="mt-10">
<h3 class="text-2xl text-black dark:text-white">
Advanced Options
</h3>
<%!-- TODO: add codec docs --%>
<.input
id="video_codec_preference_string"
name="setting[video_codec_preference_string]"
value={Enum.join(f[:video_codec_preference].value, ">")}
placeholder="avc>vp9>av01"
type="text"
label="Video Codec Preference"
help="Order of preference for video codecs. Separate with >. See below for available codecs TODO"
inputclass="font-mono text-sm mr-4"
/>
<.input
id="audio_codec_preference_string"
name="setting[audio_codec_preference_string]"
value={Enum.join(f[:audio_codec_preference].value, ">")}
placeholder="mp4a>opus>aac"
type="text"
label="Audio Codec Preference"
help="Order of preference for audio codecs. Separate with >. See below for available codecs TODO"
inputclass="font-mono text-sm mr-4"
/>
</section>
<.button class="mt-10 mb-4 sm:mb-8 w-full sm:w-auto" rounding="rounded-lg">Save Settings</.button> <.button class="mt-10 mb-4 sm:mb-8 w-full sm:w-auto" rounding="rounded-lg">Save Settings</.button>
</.simple_form> </.simple_form>