Added action button to force a metadata refresh

This commit is contained in:
Kieran Eglin 2024-04-18 15:30:26 -07:00
parent 0d969c865e
commit a9c072b9ce
No known key found for this signature in database
GPG key ID: 193984967FCF432D
6 changed files with 68 additions and 11 deletions

View file

@ -10,6 +10,7 @@ defmodule PinchflatWeb.Sources.SourceController do
alias Pinchflat.Profiles.MediaProfile alias Pinchflat.Profiles.MediaProfile
alias Pinchflat.Downloading.DownloadingHelpers alias Pinchflat.Downloading.DownloadingHelpers
alias Pinchflat.SlowIndexing.SlowIndexingHelpers alias Pinchflat.SlowIndexing.SlowIndexingHelpers
alias Pinchflat.Metadata.SourceMetadataStorageWorker
def index(conn, _params) do def index(conn, _params) do
sources = sources =
@ -104,20 +105,38 @@ defmodule PinchflatWeb.Sources.SourceController do
end end
def force_download(conn, %{"source_id" => id}) do def force_download(conn, %{"source_id" => id}) do
source = Sources.get_source!(id) wrap_forced_action(
DownloadingHelpers.enqueue_pending_download_tasks(source) conn,
id,
conn "Forcing download of pending media items.",
|> put_flash(:info, "Forced download of pending media items.") &DownloadingHelpers.enqueue_pending_download_tasks/1
|> redirect(to: ~p"/sources/#{source}") )
end end
def force_index(conn, %{"source_id" => id}) do def force_index(conn, %{"source_id" => id}) do
source = Sources.get_source!(id) wrap_forced_action(
SlowIndexingHelpers.kickoff_indexing_task(source, %{force: true}) conn,
id,
"Index enqueued.",
&SlowIndexingHelpers.kickoff_indexing_task(&1, %{force: true})
)
end
def force_metadata_refresh(conn, %{"source_id" => id}) do
wrap_forced_action(
conn,
id,
"Metadata refresh enqueued.",
&SourceMetadataStorageWorker.kickoff_with_task/1
)
end
defp wrap_forced_action(conn, source_id, message, fun) do
source = Sources.get_source!(source_id)
fun.(source)
conn conn
|> put_flash(:info, "Index enqueued.") |> put_flash(:info, message)
|> redirect(to: ~p"/sources/#{source}") |> redirect(to: ~p"/sources/#{source}")
end end

View file

@ -36,6 +36,15 @@ defmodule PinchflatWeb.Sources.SourceHTML do
|> Phoenix.json_library().encode!() |> Phoenix.json_library().encode!()
end end
def title_filter_regex_help do
url = "https://github.com/nalgeon/sqlean/blob/main/docs/regexp.md#supported-syntax"
classes = "underline decoration-bodydark decoration-1 hover:decoration-white"
"""
A PCRE-compatible regex. Only media with titles that match this regex will be downloaded. <a href="#{url}" class="#{classes}" target="_blank">See here</a> for syntax
"""
end
def output_path_template_override_help do def output_path_template_override_help do
help_button_classes = "underline decoration-bodydark decoration-1 hover:decoration-white cursor-pointer" help_button_classes = "underline decoration-bodydark decoration-1 hover:decoration-white cursor-pointer"
help_button = ~s{<span class="#{help_button_classes}" x-on:click="$dispatch('load-template')">Click here</span>} help_button = ~s{<span class="#{help_button_classes}" x-on:click="$dispatch('load-template')">Click here</span>}

View file

@ -30,6 +30,15 @@
Force Index Force Index
</.link> </.link>
</:option> </:option>
<:option>
<.link
href={~p"/sources/#{@source}/force_metadata_refresh"}
method="post"
data-confirm="Are you sure you want to refresh this source's metadata?"
>
Refresh Metadata
</.link>
</:option>
<:option> <:option>
<div class="h-px w-full bg-bodydark2"></div> <div class="h-px w-full bg-bodydark2"></div>
</:option> </:option>

View file

@ -23,7 +23,7 @@
field={f[:custom_name]} field={f[:custom_name]}
type="text" type="text"
label="Custom Name" label="Custom Name"
help="Something descriptive. Does not impact indexing or downloading" help="Does not impact indexing or downloading. Will be inferred from the source if left blank"
/> />
<.input field={f[:original_url]} type="text" label="Source URL" help="URL of a channel or playlist (required)" /> <.input field={f[:original_url]} type="text" label="Source URL" help="URL of a channel or playlist (required)" />
@ -111,7 +111,8 @@
type="text" type="text"
label="Title Filter Regex" label="Title Filter Regex"
placeholder="(?i)^How to Bike$" placeholder="(?i)^How to Bike$"
help="A PCRE-compatible regex. Only media with titles that match this regex will be downloaded. Look up 'SQLean Regex docs' for more" help={title_filter_regex_help()}
html_help={true}
/> />
<section <section

View file

@ -35,6 +35,7 @@ defmodule PinchflatWeb.Router do
resources "/sources", Sources.SourceController do resources "/sources", Sources.SourceController do
post "/force_download", Sources.SourceController, :force_download post "/force_download", Sources.SourceController, :force_download
post "/force_index", Sources.SourceController, :force_index post "/force_index", Sources.SourceController, :force_index
post "/force_metadata_refresh", Sources.SourceController, :force_metadata_refresh
resources "/media", MediaItems.MediaItemController, only: [:show, :edit, :update, :delete] do resources "/media", MediaItems.MediaItemController, only: [:show, :edit, :update, :delete] do
post "/force_download", MediaItems.MediaItemController, :force_download post "/force_download", MediaItems.MediaItemController, :force_download

View file

@ -9,6 +9,7 @@ defmodule PinchflatWeb.SourceControllerTest do
alias Pinchflat.Repo alias Pinchflat.Repo
alias Pinchflat.Settings alias Pinchflat.Settings
alias Pinchflat.Downloading.MediaDownloadWorker alias Pinchflat.Downloading.MediaDownloadWorker
alias Pinchflat.Metadata.SourceMetadataStorageWorker
alias Pinchflat.SlowIndexing.MediaCollectionIndexingWorker alias Pinchflat.SlowIndexing.MediaCollectionIndexingWorker
setup do setup do
@ -215,6 +216,23 @@ defmodule PinchflatWeb.SourceControllerTest do
end end
end end
describe "force_metadata_refresh" do
test "forces a metadata refresh", %{conn: conn} do
source = source_fixture()
assert [] = all_enqueued(worker: SourceMetadataStorageWorker)
post(conn, ~p"/sources/#{source.id}/force_metadata_refresh")
assert [_] = all_enqueued(worker: SourceMetadataStorageWorker)
end
test "redirects to the source page", %{conn: conn} do
source = source_fixture()
conn = post(conn, ~p"/sources/#{source.id}/force_metadata_refresh")
assert redirected_to(conn) == ~p"/sources/#{source.id}"
end
end
defp create_source(_) do defp create_source(_) do
source = source_fixture() source = source_fixture()
media_item = media_item_with_attachments(%{source_id: source.id}) media_item = media_item_with_attachments(%{source_id: source.id})