Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bf74a04e7 | |||
| 33040bba34 | |||
| b1a6a6a81f | |||
| a7b0af65e2 | |||
| dcf033f10a | |||
| 8d9bd11882 | |||
| bdcb49185a | |||
| 1f1cd1cb63 | |||
| d575548226 |
+2
-1
@@ -16,7 +16,8 @@
|
|||||||
"Config.HTTPS",
|
"Config.HTTPS",
|
||||||
"Config.CSP",
|
"Config.CSP",
|
||||||
"XSS.ContentType",
|
"XSS.ContentType",
|
||||||
"Traversal.SendFile"
|
"Traversal.SendFile",
|
||||||
|
"Traversal.SendDownload"
|
||||||
],
|
],
|
||||||
ignore_files: [],
|
ignore_files: [],
|
||||||
version: false
|
version: false
|
||||||
|
|||||||
+3
-2
@@ -53,7 +53,7 @@ if config_env() == :prod do
|
|||||||
# For testing alternate journal modes (see issue #137)
|
# For testing alternate journal modes (see issue #137)
|
||||||
journal_mode = String.to_existing_atom(System.get_env("JOURNAL_MODE", "wal"))
|
journal_mode = String.to_existing_atom(System.get_env("JOURNAL_MODE", "wal"))
|
||||||
|
|
||||||
config :logger, level: String.to_existing_atom(System.get_env("LOG_LEVEL", "info"))
|
config :logger, level: String.to_existing_atom(System.get_env("LOG_LEVEL", "debug"))
|
||||||
|
|
||||||
config :pinchflat,
|
config :pinchflat,
|
||||||
yt_dlp_executable: System.find_executable("yt-dlp"),
|
yt_dlp_executable: System.find_executable("yt-dlp"),
|
||||||
@@ -64,7 +64,8 @@ if config_env() == :prod do
|
|||||||
tmpfile_directory: Path.join([System.tmp_dir!(), "pinchflat", "data"]),
|
tmpfile_directory: Path.join([System.tmp_dir!(), "pinchflat", "data"]),
|
||||||
dns_cluster_query: System.get_env("DNS_CLUSTER_QUERY"),
|
dns_cluster_query: System.get_env("DNS_CLUSTER_QUERY"),
|
||||||
expose_feed_endpoints: expose_feed_endpoints,
|
expose_feed_endpoints: expose_feed_endpoints,
|
||||||
timezone: System.get_env("TIMEZONE") || System.get_env("TZ") || "UTC"
|
timezone: System.get_env("TIMEZONE") || System.get_env("TZ") || "UTC",
|
||||||
|
log_path: log_path
|
||||||
|
|
||||||
config :tzdata, :data_dir, System.get_env("TZ_DATA_DIR", "/etc/elixir_tzdata_data")
|
config :tzdata, :data_dir, System.get_env("TZ_DATA_DIR", "/etc/elixir_tzdata_data")
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||||||
"""
|
"""
|
||||||
@impl true
|
@impl true
|
||||||
def init(state) do
|
def init(state) do
|
||||||
|
ensure_tmpfile_directory()
|
||||||
reset_executing_jobs()
|
reset_executing_jobs()
|
||||||
create_blank_yt_dlp_files()
|
create_blank_yt_dlp_files()
|
||||||
create_blank_user_script_file()
|
create_blank_user_script_file()
|
||||||
@@ -39,6 +40,14 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp ensure_tmpfile_directory do
|
||||||
|
tmpfile_dir = Application.get_env(:pinchflat, :tmpfile_directory)
|
||||||
|
|
||||||
|
if !File.exists?(tmpfile_dir) do
|
||||||
|
File.mkdir_p!(tmpfile_dir)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# If a node cannot gracefully shut down, the currently executing jobs get stuck
|
# If a node cannot gracefully shut down, the currently executing jobs get stuck
|
||||||
# in the "executing" state. This is a problem because the job runner will not
|
# in the "executing" state. This is a problem because the job runner will not
|
||||||
# pick them up again
|
# pick them up again
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ defmodule Pinchflat.Lifecycle.Notifications.CommandRunner do
|
|||||||
parsed_opts = CliUtils.parse_options(default_opts ++ command_opts)
|
parsed_opts = CliUtils.parse_options(default_opts ++ command_opts)
|
||||||
|
|
||||||
{output, exit_code} = CliUtils.wrap_cmd(backend_executable(), parsed_opts ++ endpoints)
|
{output, exit_code} = CliUtils.wrap_cmd(backend_executable(), parsed_opts ++ endpoints)
|
||||||
Logger.info("[apprise] response: #{output}")
|
|
||||||
|
|
||||||
case exit_code do
|
case exit_code do
|
||||||
0 -> {:ok, String.trim(output)}
|
0 -> {:ok, String.trim(output)}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do
|
|||||||
{:ok, executable_path} ->
|
{:ok, executable_path} ->
|
||||||
{:ok, encoded_data} = Phoenix.json_library().encode(encodable_data)
|
{:ok, encoded_data} = Phoenix.json_library().encode(encodable_data)
|
||||||
|
|
||||||
{output, exit_code} =
|
{_output, _exit_code} =
|
||||||
CliUtils.wrap_cmd(
|
CliUtils.wrap_cmd(
|
||||||
executable_path,
|
executable_path,
|
||||||
[to_string(event_type), encoded_data],
|
[to_string(event_type), encoded_data],
|
||||||
@@ -47,7 +47,7 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do
|
|||||||
logging_arg_override: "[suppressed]"
|
logging_arg_override: "[suppressed]"
|
||||||
)
|
)
|
||||||
|
|
||||||
handle_output(output, exit_code)
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -55,12 +55,6 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do
|
|||||||
raise ArgumentError, "Invalid event type: #{inspect(event_type)}"
|
raise ArgumentError, "Invalid event type: #{inspect(event_type)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
defp handle_output(output, exit_code) do
|
|
||||||
Logger.debug("Custom lifecycle script exit code: #{exit_code} with output: #{output}")
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
defp backend_executable do
|
defp backend_executable do
|
||||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||||
filepath = Path.join([base_dir, "user-scripts", "lifecycle"])
|
filepath = Path.join([base_dir, "user-scripts", "lifecycle"])
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ defmodule Pinchflat.Podcasts.PodcastHelpers do
|
|||||||
Returns: [%MediaItem{}]
|
Returns: [%MediaItem{}]
|
||||||
"""
|
"""
|
||||||
def persisted_media_items_for(source, opts \\ []) do
|
def persisted_media_items_for(source, opts \\ []) do
|
||||||
limit = Keyword.get(opts, :limit, 500)
|
limit = Keyword.get(opts, :limit, 1_000)
|
||||||
|
|
||||||
MediaQuery.new()
|
MediaQuery.new()
|
||||||
|> MediaQuery.for_source(source)
|
|> MediaQuery.for_source(source)
|
||||||
|> MediaQuery.with_media_filepath()
|
|> MediaQuery.with_media_filepath()
|
||||||
|
|> order_by(desc: :upload_date)
|
||||||
|> Repo.maybe_limit(limit)
|
|> Repo.maybe_limit(limit)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.filter(fn media_item -> File.exists?(media_item.media_filepath) end)
|
|> Enum.filter(fn media_item -> File.exists?(media_item.media_filepath) end)
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
|
|||||||
Only MediaItems that have been persisted will be included in the feed.
|
Only MediaItems that have been persisted will be included in the feed.
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
- `:limit` - The maximum number of media items to include in the feed. Defaults to 300.
|
- `:limit` - The maximum number of media items to include in the feed. Defaults to 2,000.
|
||||||
|
|
||||||
Returns an XML document as a string.
|
Returns an XML document as a string.
|
||||||
"""
|
"""
|
||||||
def build(source, opts \\ []) do
|
def build(source, opts \\ []) do
|
||||||
limit = Keyword.get(opts, :limit, 300)
|
limit = Keyword.get(opts, :limit, 2_000)
|
||||||
url_base = Keyword.get(opts, :url_base, PinchflatWeb.Endpoint.url())
|
url_base = Keyword.get(opts, :url_base, PinchflatWeb.Endpoint.url())
|
||||||
|
|
||||||
media_items = PodcastHelpers.persisted_media_items_for(source, limit: limit)
|
media_items = PodcastHelpers.persisted_media_items_for(source, limit: limit)
|
||||||
|
|||||||
@@ -24,11 +24,15 @@ defmodule Pinchflat.Utils.CliUtils do
|
|||||||
def wrap_cmd(command, args, passthrough_opts \\ [], opts \\ []) do
|
def wrap_cmd(command, args, passthrough_opts \\ [], opts \\ []) do
|
||||||
wrapper_command = Path.join(:code.priv_dir(:pinchflat), "cmd_wrapper.sh")
|
wrapper_command = Path.join(:code.priv_dir(:pinchflat), "cmd_wrapper.sh")
|
||||||
actual_command = [command] ++ args
|
actual_command = [command] ++ args
|
||||||
|
command_opts = set_command_opts() ++ passthrough_opts
|
||||||
logging_arg_override = Keyword.get(opts, :logging_arg_override, Enum.join(args, " "))
|
logging_arg_override = Keyword.get(opts, :logging_arg_override, Enum.join(args, " "))
|
||||||
|
|
||||||
Logger.info("[command_wrapper]: #{command} called with: #{logging_arg_override}")
|
Logger.info("[command_wrapper]: #{command} called with: #{logging_arg_override}")
|
||||||
|
|
||||||
System.cmd(wrapper_command, actual_command, passthrough_opts)
|
{output, status} = System.cmd(wrapper_command, actual_command, command_opts)
|
||||||
|
log_cmd_result(command, logging_arg_override, status, output)
|
||||||
|
|
||||||
|
{output, status}
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@@ -71,4 +75,20 @@ defmodule Pinchflat.Utils.CliUtils do
|
|||||||
defp parse_option(arg, acc) when is_binary(arg) do
|
defp parse_option(arg, acc) when is_binary(arg) do
|
||||||
acc ++ [arg]
|
acc ++ [arg]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp log_cmd_result(command, logging_arg_override, status, output) do
|
||||||
|
log_message = "[command_wrapper]: #{command} called with: #{logging_arg_override} exited: #{status} with: #{output}"
|
||||||
|
log_level = if status == 0, do: :debug, else: :error
|
||||||
|
|
||||||
|
Logger.log(log_level, log_message)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp set_command_opts do
|
||||||
|
# This resolves an issue where yt-dlp would attempt to write to a read-only directory
|
||||||
|
# if you scanned a new video with `--windows-filenames` enabled. Hopefully can be removed
|
||||||
|
# in the future.
|
||||||
|
[
|
||||||
|
cd: Application.get_env(:pinchflat, :tmpfile_directory)
|
||||||
|
]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
|||||||
|
|
||||||
output_filepath = generate_output_filepath(addl_opts)
|
output_filepath = generate_output_filepath(addl_opts)
|
||||||
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
||||||
user_configured_opts = cookie_file_options() ++ global_options()
|
user_configured_opts = cookie_file_options()
|
||||||
# These must stay in exactly this order, hence why I'm giving it its own variable.
|
# These must stay in exactly this order, hence why I'm giving it its own variable.
|
||||||
all_opts = command_opts ++ print_to_file_opts ++ user_configured_opts
|
all_opts = command_opts ++ print_to_file_opts ++ user_configured_opts ++ global_options()
|
||||||
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
||||||
|
|
||||||
case CliUtils.wrap_cmd(command, formatted_command_opts, stderr_to_stdout: true) do
|
case CliUtils.wrap_cmd(command, formatted_command_opts, stderr_to_stdout: true) do
|
||||||
@@ -71,7 +71,11 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp global_options do
|
defp global_options do
|
||||||
[:windows_filenames]
|
[
|
||||||
|
:windows_filenames,
|
||||||
|
:quiet,
|
||||||
|
cache_dir: Path.join(Application.get_env(:pinchflat, :tmpfile_directory), "yt-dlp-cache")
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
defp cookie_file_options do
|
defp cookie_file_options do
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ defmodule Pinchflat.YtDlp.MediaCollection do
|
|||||||
# `ignore_no_formats_error` is necessary because yt-dlp will error out if
|
# `ignore_no_formats_error` is necessary because yt-dlp will error out if
|
||||||
# the first video has not released yet (ie: is a premier). We don't care about
|
# the first video has not released yet (ie: is a premier). We don't care about
|
||||||
# available formats since we're just getting the media details
|
# available formats since we're just getting the media details
|
||||||
command_opts = [:simulate, :skip_download, :ignore_no_formats_error]
|
command_opts = [:simulate, :skip_download, :ignore_no_formats_error, :no_warnings]
|
||||||
output_template = YtDlpMedia.indexing_output_template()
|
output_template = YtDlpMedia.indexing_output_template()
|
||||||
output_filepath = FilesystemUtils.generate_metadata_tmpfile(:json)
|
output_filepath = FilesystemUtils.generate_metadata_tmpfile(:json)
|
||||||
file_listener_handler = Keyword.get(addl_opts, :file_listener_handler, false)
|
file_listener_handler = Keyword.get(addl_opts, :file_listener_handler, false)
|
||||||
|
|||||||
@@ -4,28 +4,107 @@ defmodule PinchflatWeb.Layouts do
|
|||||||
embed_templates "layouts/*"
|
embed_templates "layouts/*"
|
||||||
embed_templates "layouts/partials/*"
|
embed_templates "layouts/partials/*"
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Renders a sidebar menu item link
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
<.sidebar_link icon="hero-home" text="Home" href="/" />
|
||||||
|
"""
|
||||||
attr :icon, :string, required: true
|
attr :icon, :string, required: true
|
||||||
attr :text, :string, required: true
|
attr :text, :string, required: true
|
||||||
attr :href, :any, required: true
|
attr :href, :any, required: true
|
||||||
attr :target, :any, default: "_self"
|
attr :target, :any, default: "_self"
|
||||||
|
|
||||||
def sidebar_item(assigns) do
|
def sidebar_item(assigns) do
|
||||||
# I'm testing out grouping classes here. Tentative order: font, layout, color, animation, state-modifiers
|
|
||||||
~H"""
|
~H"""
|
||||||
<li>
|
<li class="text-bodydark1">
|
||||||
<.link
|
<.sidebar_link icon={@icon} text={@text} href={@href} target={@target} />
|
||||||
href={@href}
|
|
||||||
target={@target}
|
|
||||||
class={[
|
|
||||||
"font-medium text-bodydark1",
|
|
||||||
"group relative flex items-center gap-2.5 rounded-sm px-4 py-2 duration-300 ease-in-out",
|
|
||||||
"duration-300 ease-in-out",
|
|
||||||
"hover:bg-graydark dark:hover:bg-meta-4"
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<.icon name={@icon} /> <%= @text %>
|
|
||||||
</.link>
|
|
||||||
</li>
|
</li>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Renders a sidebar menu item with a submenu
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
<.sidebar_submenu icon="hero-home" text="Home" current_path="/">
|
||||||
|
<:submenu icon="hero-home" text="Home" href="/" />
|
||||||
|
</.sidebar_submenu>
|
||||||
|
"""
|
||||||
|
|
||||||
|
attr :icon, :string, required: true
|
||||||
|
attr :text, :string, required: true
|
||||||
|
attr :current_path, :string, required: true
|
||||||
|
|
||||||
|
slot :submenu do
|
||||||
|
attr :icon, :string
|
||||||
|
attr :text, :string
|
||||||
|
attr :href, :any
|
||||||
|
attr :target, :any
|
||||||
|
end
|
||||||
|
|
||||||
|
def sidebar_submenu(assigns) do
|
||||||
|
initially_selected = Enum.any?(assigns[:submenu], &(&1[:href] == assigns[:current_path]))
|
||||||
|
assigns = Map.put(assigns, :initially_selected, initially_selected)
|
||||||
|
|
||||||
|
~H"""
|
||||||
|
<li class="text-bodydark1" x-data={"{ selected: #{@initially_selected} }"}>
|
||||||
|
<span
|
||||||
|
class={[
|
||||||
|
"font-medium cursor-pointer",
|
||||||
|
"group relative flex items-center justify-between rounded-sm px-4 py-2 duration-300 ease-in-out",
|
||||||
|
"duration-300 ease-in-out",
|
||||||
|
"hover:bg-meta-4"
|
||||||
|
]}
|
||||||
|
x-on:click="selected = !selected"
|
||||||
|
>
|
||||||
|
<span class="flex items-center gap-2.5">
|
||||||
|
<.icon name={@icon} /> <%= @text %>
|
||||||
|
</span>
|
||||||
|
<span class="text-bodydark2">
|
||||||
|
<.icon name="hero-chevron-up" x-bind:class="{ 'rotate-180': selected }" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<ul x-bind:class="selected ? 'block' :'hidden'">
|
||||||
|
<li :for={menu <- @submenu} class="text-bodydark2">
|
||||||
|
<.sidebar_link icon={menu[:icon]} text={menu[:text]} href={menu[:href]} target={menu[:target]} class="pl-10" />
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Renders a sidebar menu item link
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
<.sidebar_link icon="hero-home" text="Home" href="/" />
|
||||||
|
"""
|
||||||
|
attr :icon, :string
|
||||||
|
attr :text, :string, required: true
|
||||||
|
attr :href, :any, required: true
|
||||||
|
attr :target, :any, default: "_self"
|
||||||
|
attr :class, :string, default: ""
|
||||||
|
|
||||||
|
def sidebar_link(assigns) do
|
||||||
|
~H"""
|
||||||
|
<.link
|
||||||
|
href={@href}
|
||||||
|
target={@target}
|
||||||
|
class={[
|
||||||
|
"font-medium",
|
||||||
|
"group relative flex items-center gap-2.5 rounded-sm px-4 py-2 duration-300 ease-in-out",
|
||||||
|
"duration-300 ease-in-out",
|
||||||
|
"hover:bg-meta-4",
|
||||||
|
@class
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<.icon :if={@icon} name={@icon} /> <%= @text %>
|
||||||
|
</.link>
|
||||||
|
"""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div class="flex h-screen overflow-hidden">
|
<div class="flex h-screen overflow-hidden">
|
||||||
<.sidebar />
|
<.sidebar conn={@conn} />
|
||||||
|
|
||||||
<div class="relative flex flex-1 flex-col overflow-y-auto overflow-x-hidden">
|
<div class="relative flex flex-1 flex-col overflow-y-auto overflow-x-hidden">
|
||||||
<.header params={@conn.params} />
|
<.header params={@conn.params} />
|
||||||
|
|||||||
@@ -26,7 +26,14 @@
|
|||||||
<.sidebar_item icon="hero-home" text="Home" href={~p"/"} />
|
<.sidebar_item icon="hero-home" text="Home" href={~p"/"} />
|
||||||
<.sidebar_item icon="hero-tv" text="Sources" href={~p"/sources"} />
|
<.sidebar_item icon="hero-tv" text="Sources" href={~p"/sources"} />
|
||||||
<.sidebar_item icon="hero-adjustments-vertical" text="Media Profiles" href={~p"/media_profiles"} />
|
<.sidebar_item icon="hero-adjustments-vertical" text="Media Profiles" href={~p"/media_profiles"} />
|
||||||
<.sidebar_item icon="hero-cog-6-tooth" text="Settings" href={~p"/settings"} />
|
<.sidebar_submenu
|
||||||
|
icon="hero-cog-6-tooth"
|
||||||
|
text="Config"
|
||||||
|
current_path={Phoenix.Controller.current_path(@conn)}
|
||||||
|
>
|
||||||
|
<:submenu text="Settings" href={~p"/settings"} />
|
||||||
|
<:submenu text="App Info" href={~p"/app_info"} />
|
||||||
|
</.sidebar_submenu>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
<p class="mt-4">
|
<p class="mt-4">
|
||||||
To unlock Pro, simply type
|
To unlock Pro, simply type
|
||||||
<.inline_code>got it!</.inline_code>
|
<.inline_code>got it</.inline_code>
|
||||||
into the text box and press the button.
|
into the text box and press the button.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ defmodule PinchflatWeb.Podcasts.PodcastController do
|
|||||||
def rss_feed(conn, %{"uuid" => uuid}) do
|
def rss_feed(conn, %{"uuid" => uuid}) do
|
||||||
source = Repo.get_by!(Source, uuid: uuid)
|
source = Repo.get_by!(Source, uuid: uuid)
|
||||||
url_base = url(conn, ~p"/")
|
url_base = url(conn, ~p"/")
|
||||||
xml = RssFeedBuilder.build(source, limit: 300, url_base: url_base)
|
xml = RssFeedBuilder.build(source, limit: 2_000, url_base: url_base)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/rss+xml")
|
|> put_resp_content_type("application/rss+xml")
|
||||||
|
|||||||
@@ -23,4 +23,20 @@ defmodule PinchflatWeb.Settings.SettingController do
|
|||||||
render(conn, "show.html", changeset: changeset)
|
render(conn, "show.html", changeset: changeset)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def app_info(conn, _params) do
|
||||||
|
render(conn, "app_info.html")
|
||||||
|
end
|
||||||
|
|
||||||
|
def download_logs(conn, _params) do
|
||||||
|
log_path = Application.get_env(:pinchflat, :log_path)
|
||||||
|
|
||||||
|
if log_path && File.exists?(log_path) do
|
||||||
|
send_download(conn, {:file, log_path}, filename: "pinchflat-logs-#{Date.utc_today()}.txt")
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> put_flash(:error, "Log file couldn't be found")
|
||||||
|
|> redirect(to: ~p"/app_info")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,4 +18,14 @@ defmodule PinchflatWeb.Settings.SettingHTML do
|
|||||||
|
|
||||||
~s(Server endpoint for Apprise notifications when new media is found. See <a href="#{url}" class="#{classes}" target="_blank">Apprise docs</a> for more information)
|
~s(Server endpoint for Apprise notifications when new media is found. See <a href="#{url}" class="#{classes}" target="_blank">Apprise docs</a> for more information)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def diagnostic_info_string do
|
||||||
|
"""
|
||||||
|
App Version: #{Application.spec(:pinchflat)[:vsn]}
|
||||||
|
yt-dlp Version: #{Settings.get!(:yt_dlp_version)}
|
||||||
|
Apprise Version: #{Settings.get!(:apprise_version)}
|
||||||
|
System Architecture: #{to_string(:erlang.system_info(:system_architecture))}
|
||||||
|
Timezone: #{Application.get_env(:pinchflat, :timezone)}
|
||||||
|
"""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<div class="mb-6 flex gap-3 flex-row items-center justify-between">
|
||||||
|
<div class="flex gap-3 items-center">
|
||||||
|
<h2 class="text-title-md2 font-bold text-white ml-4">
|
||||||
|
App Info
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="rounded-sm border border-stroke bg-white px-5 py-5 shadow-default dark:border-strokedark dark:bg-boxdark sm:px-7.5">
|
||||||
|
<div class="max-w-full">
|
||||||
|
<.button color="bg-primary" rounding="rounded-lg" x-data="{ copied: false }" x-on:click={~s"
|
||||||
|
copyWithCallbacks(
|
||||||
|
`#{diagnostic_info_string()}`,
|
||||||
|
() => copied = true,
|
||||||
|
() => copied = false
|
||||||
|
)
|
||||||
|
"}>
|
||||||
|
Copy Diagnostic Info
|
||||||
|
<span x-show="copied" x-transition.duration.150ms><.icon name="hero-check" class="ml-2 h-4 w-4" /></span>
|
||||||
|
</.button>
|
||||||
|
<.link href={~p"/download_logs"}>
|
||||||
|
<.button color="bg-primary" rounding="rounded-lg" class="ml-4">
|
||||||
|
Download Logs
|
||||||
|
</.button>
|
||||||
|
</.link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -30,7 +30,10 @@ defmodule PinchflatWeb.Router do
|
|||||||
|
|
||||||
resources "/media_profiles", MediaProfiles.MediaProfileController
|
resources "/media_profiles", MediaProfiles.MediaProfileController
|
||||||
resources "/search", Searches.SearchController, only: [:show], singleton: true
|
resources "/search", Searches.SearchController, only: [:show], singleton: true
|
||||||
|
|
||||||
resources "/settings", Settings.SettingController, only: [:show, :update], singleton: true
|
resources "/settings", Settings.SettingController, only: [:show, :update], singleton: true
|
||||||
|
get "/app_info", Settings.SettingController, :app_info
|
||||||
|
get "/download_logs", Settings.SettingController, :download_logs
|
||||||
|
|
||||||
resources "/sources", Sources.SourceController do
|
resources "/sources", Sources.SourceController do
|
||||||
post "/force_download_pending", Sources.SourceController, :force_download_pending
|
post "/force_download_pending", Sources.SourceController, :force_download_pending
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ defmodule Pinchflat.MixProject do
|
|||||||
def project do
|
def project do
|
||||||
[
|
[
|
||||||
app: :pinchflat,
|
app: :pinchflat,
|
||||||
version: "2024.5.14",
|
version: "2024.5.16",
|
||||||
elixir: "~> 1.16",
|
elixir: "~> 1.16",
|
||||||
elixirc_paths: elixirc_paths(Mix.env()),
|
elixirc_paths: elixirc_paths(Mix.env()),
|
||||||
start_permanent: Mix.env() == :prod,
|
start_permanent: Mix.env() == :prod,
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
defmodule Pinchflat.Repo.Migrations.AddDateIndexesToMediaItems do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create(index(:media_items, [:media_downloaded_at]))
|
||||||
|
create(index(:media_items, [:media_redownloaded_at]))
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -13,6 +13,19 @@ defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
|||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "ensure_tmpfile_directory" do
|
||||||
|
test "creates the tmpfile directory if it doesn't exist" do
|
||||||
|
tmpfile_dir = Application.get_env(:pinchflat, :tmpfile_directory)
|
||||||
|
File.rm_rf!(tmpfile_dir)
|
||||||
|
|
||||||
|
refute File.exists?(tmpfile_dir)
|
||||||
|
|
||||||
|
PreJobStartupTasks.init(%{})
|
||||||
|
|
||||||
|
assert File.exists?(tmpfile_dir)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "reset_executing_jobs" do
|
describe "reset_executing_jobs" do
|
||||||
test "resets executing jobs" do
|
test "resets executing jobs" do
|
||||||
job = job_fixture()
|
job = job_fixture()
|
||||||
@@ -78,6 +91,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
|||||||
|
|
||||||
describe "apply_default_settings" do
|
describe "apply_default_settings" do
|
||||||
test "sets yt_dlp version" do
|
test "sets yt_dlp version" do
|
||||||
|
File.rm_rf!(Application.get_env(:pinchflat, :tmpfile_directory))
|
||||||
Settings.set(yt_dlp_version: nil)
|
Settings.set(yt_dlp_version: nil)
|
||||||
|
|
||||||
refute Settings.get!(:yt_dlp_version)
|
refute Settings.get!(:yt_dlp_version)
|
||||||
@@ -88,6 +102,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "sets apprise version" do
|
test "sets apprise version" do
|
||||||
|
File.rm_rf!(Application.get_env(:pinchflat, :tmpfile_directory))
|
||||||
Settings.set(apprise_version: nil)
|
Settings.set(apprise_version: nil)
|
||||||
|
|
||||||
refute Settings.get!(:apprise_version)
|
refute Settings.get!(:apprise_version)
|
||||||
|
|||||||
@@ -22,6 +22,16 @@ defmodule Pinchflat.Podcasts.PodcastHelpersTest do
|
|||||||
|
|
||||||
assert [] = PodcastHelpers.persisted_media_items_for(source, limit: 0)
|
assert [] = PodcastHelpers.persisted_media_items_for(source, limit: 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "orders by upload date where newest is first" do
|
||||||
|
source = source_fixture()
|
||||||
|
|
||||||
|
oldest = media_item_with_attachments(%{source_id: source.id, upload_date: now_minus(2, :day)})
|
||||||
|
current = media_item_with_attachments(%{source_id: source.id, upload_date: now()})
|
||||||
|
older = media_item_with_attachments(%{source_id: source.id, upload_date: now_minus(1, :days)})
|
||||||
|
|
||||||
|
assert [^current, ^older, ^oldest] = PodcastHelpers.persisted_media_items_for(source)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "select_cover_image/2" do
|
describe "select_cover_image/2" do
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ defmodule Pinchflat.Utils.CliUtilsTest do
|
|||||||
test "delegates to System.cmd/3" do
|
test "delegates to System.cmd/3" do
|
||||||
assert {"output\n", 0} = CliUtils.wrap_cmd("echo", ["output"])
|
assert {"output\n", 0} = CliUtils.wrap_cmd("echo", ["output"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "sets the current directory to the tmp dir" do
|
||||||
|
assert {"/tmp/test/tmpfiles\n", 0} = CliUtils.wrap_cmd("pwd", [])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "parse_options/1" do
|
describe "parse_options/1" do
|
||||||
|
|||||||
@@ -87,6 +87,18 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do
|
|||||||
|
|
||||||
assert String.contains?(output, "--windows-filenames")
|
assert String.contains?(output, "--windows-filenames")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "runs quietly" do
|
||||||
|
assert {:ok, output} = Runner.run(@media_url, [], "")
|
||||||
|
|
||||||
|
assert String.contains?(output, "--quiet")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "sets the cache directory" do
|
||||||
|
assert {:ok, output} = Runner.run(@media_url, [], "")
|
||||||
|
|
||||||
|
assert String.contains?(output, "--cache-dir /tmp/test/tmpfiles/yt-dlp-cache")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "version/0" do
|
describe "version/0" do
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
|||||||
|
|
||||||
test "it passes the expected default args" do
|
test "it passes the expected default args" do
|
||||||
expect(YtDlpRunnerMock, :run, fn _url, opts, ot, _addl_opts ->
|
expect(YtDlpRunnerMock, :run, fn _url, opts, ot, _addl_opts ->
|
||||||
assert opts == [:simulate, :skip_download, :ignore_no_formats_error]
|
assert opts == [:simulate, :skip_download, :ignore_no_formats_error, :no_warnings]
|
||||||
assert ot == Media.indexing_output_template()
|
assert ot == Media.indexing_output_template()
|
||||||
|
|
||||||
{:ok, ""}
|
{:ok, ""}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
defmodule PinchflatWeb.SettingControllerTest do
|
defmodule PinchflatWeb.SettingControllerTest do
|
||||||
use PinchflatWeb.ConnCase
|
use PinchflatWeb.ConnCase
|
||||||
|
|
||||||
|
alias Pinchflat.Utils.FilesystemUtils
|
||||||
|
|
||||||
describe "show settings" do
|
describe "show settings" do
|
||||||
test "renders the page", %{conn: conn} do
|
test "renders the page", %{conn: conn} do
|
||||||
conn = get(conn, ~p"/settings")
|
conn = get(conn, ~p"/settings")
|
||||||
@@ -20,4 +22,33 @@ defmodule PinchflatWeb.SettingControllerTest do
|
|||||||
assert html_response(conn, 200) =~ update_attrs[:apprise_server]
|
assert html_response(conn, 200) =~ update_attrs[:apprise_server]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "app_info" do
|
||||||
|
test "renders the page", %{conn: conn} do
|
||||||
|
conn = get(conn, ~p"/app_info")
|
||||||
|
|
||||||
|
assert html_response(conn, 200) =~ "App Info"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "download_logs" do
|
||||||
|
test "downloads logs", %{conn: conn} do
|
||||||
|
log_path = Path.join([System.tmp_dir!(), "pinchflat", "data", "pinchflat.log"])
|
||||||
|
FilesystemUtils.write_p(log_path, "test log data")
|
||||||
|
Application.put_env(:pinchflat, :log_path, log_path)
|
||||||
|
|
||||||
|
conn = get(conn, ~p"/download_logs")
|
||||||
|
|
||||||
|
assert response(conn, 200) =~ "test log data"
|
||||||
|
|
||||||
|
Application.put_env(:pinchflat, :log_path, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "redirects when log file is not found", %{conn: conn} do
|
||||||
|
conn = get(conn, ~p"/download_logs")
|
||||||
|
|
||||||
|
assert redirected_to(conn) == ~p"/app_info"
|
||||||
|
assert conn.assigns[:flash]["error"] == "Log file couldn't be found"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user