diff --git a/lib/pinchflat_web/components/custom_components/table_components.ex b/lib/pinchflat_web/components/custom_components/table_components.ex index 532fba1..fa283d3 100644 --- a/lib/pinchflat_web/components/custom_components/table_components.ex +++ b/lib/pinchflat_web/components/custom_components/table_components.ex @@ -27,21 +27,20 @@ defmodule PinchflatWeb.CustomComponents.TableComponents do def table(assigns) do ~H""" - +
- - + - +
+
<%= col[:label] %>
length(@rows) && "border-b border-[#eee] dark:border-π", + "px-4 py-5 pl-9 xl:pl-11", col[:class] ]} > diff --git a/lib/pinchflat_web/controllers/sources/source_controller.ex b/lib/pinchflat_web/controllers/sources/source_controller.ex index 8de11f2..3b9c5b2 100644 --- a/lib/pinchflat_web/controllers/sources/source_controller.ex +++ b/lib/pinchflat_web/controllers/sources/source_controller.ex @@ -104,7 +104,7 @@ defmodule PinchflatWeb.Sources.SourceController do |> redirect(to: ~p"/sources") end - def force_download(conn, %{"source_id" => id}) do + def force_download_pending(conn, %{"source_id" => id}) do wrap_forced_action( conn, id, @@ -113,6 +113,15 @@ defmodule PinchflatWeb.Sources.SourceController do ) end + def force_redownload(conn, %{"source_id" => id}) do + wrap_forced_action( + conn, + id, + "Forcing re-download of downloaded media items.", + &DownloadingHelpers.kickoff_redownload_for_existing_media/1 + ) + end + def force_index(conn, %{"source_id" => id}) do wrap_forced_action( conn, diff --git a/lib/pinchflat_web/controllers/sources/source_html/actions_dropdown.html.heex b/lib/pinchflat_web/controllers/sources/source_html/actions_dropdown.html.heex index 617ddb1..ab5b7c1 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/actions_dropdown.html.heex +++ b/lib/pinchflat_web/controllers/sources/source_html/actions_dropdown.html.heex @@ -31,11 +31,20 @@ <:option :if={@source.download_media}> <.link - href={~p"/sources/#{@source}/force_download"} + href={~p"/sources/#{@source}/force_download_pending"} method="post" data-confirm="Are you sure you want to force a download of all *pending* media items? This isn't normally needed." > - Force Download + Download Pending + + + <:option :if={@source.download_media}> + <.link + href={~p"/sources/#{@source}/force_redownload"} + method="post" + data-confirm="Are you sure you want to re-download all currently downloaded media items? This isn't normally needed and won't change anything if the files already exist." + > + Redownload Existing <:option> diff --git a/lib/pinchflat_web/router.ex b/lib/pinchflat_web/router.ex index 2829315..e3dd14e 100644 --- a/lib/pinchflat_web/router.ex +++ b/lib/pinchflat_web/router.ex @@ -33,7 +33,8 @@ defmodule PinchflatWeb.Router do resources "/settings", Settings.SettingController, only: [:show, :update], singleton: true resources "/sources", Sources.SourceController do - post "/force_download", Sources.SourceController, :force_download + post "/force_download_pending", Sources.SourceController, :force_download_pending + post "/force_redownload", Sources.SourceController, :force_redownload post "/force_index", Sources.SourceController, :force_index post "/force_metadata_refresh", Sources.SourceController, :force_metadata_refresh diff --git a/test/pinchflat/downloading/downloading_helpers_test.exs b/test/pinchflat/downloading/downloading_helpers_test.exs index f8bc2ae..23c493d 100644 --- a/test/pinchflat/downloading/downloading_helpers_test.exs +++ b/test/pinchflat/downloading/downloading_helpers_test.exs @@ -114,7 +114,7 @@ defmodule Pinchflat.Downloading.DownloadingHelpersTest do describe "kickoff_redownload_for_existing_media/1" do test "enqueues a download job for each downloaded media item" do source = source_fixture() - media_item = media_item_fixture(source_id: source.id, media_downloaded_at: DateTime.utc_now()) + media_item = media_item_fixture(source_id: source.id, media_downloaded_at: now()) assert [{:ok, _}] = DownloadingHelpers.kickoff_redownload_for_existing_media(source) @@ -125,13 +125,13 @@ defmodule Pinchflat.Downloading.DownloadingHelpersTest do source = source_fixture() other_source = source_fixture() _not_downloaded = media_item_fixture(source_id: source.id, media_downloaded_at: nil) - _other_source = media_item_fixture(source_id: other_source.id, media_downloaded_at: DateTime.utc_now()) + _other_source = media_item_fixture(source_id: other_source.id, media_downloaded_at: now()) _download_prevented = - media_item_fixture(source_id: source.id, media_downloaded_at: DateTime.utc_now(), prevent_download: true) + media_item_fixture(source_id: source.id, media_downloaded_at: now(), prevent_download: true) _culled = - media_item_fixture(source_id: source.id, media_downloaded_at: DateTime.utc_now(), culled_at: DateTime.utc_now()) + media_item_fixture(source_id: source.id, media_downloaded_at: now(), culled_at: now()) assert [] = DownloadingHelpers.kickoff_redownload_for_existing_media(source) diff --git a/test/pinchflat_web/controllers/source_controller_test.exs b/test/pinchflat_web/controllers/source_controller_test.exs index 88cc772..b9d6882 100644 --- a/test/pinchflat_web/controllers/source_controller_test.exs +++ b/test/pinchflat_web/controllers/source_controller_test.exs @@ -166,20 +166,38 @@ defmodule PinchflatWeb.SourceControllerTest do end end - describe "force_download" do + describe "force_download_pending" do test "enqueues pending download tasks", %{conn: conn} do source = source_fixture() _media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil}) assert [] = all_enqueued(worker: MediaDownloadWorker) - post(conn, ~p"/sources/#{source.id}/force_download") + post(conn, ~p"/sources/#{source.id}/force_download_pending") assert [_] = all_enqueued(worker: MediaDownloadWorker) end test "redirects to the source page", %{conn: conn} do source = source_fixture() - conn = post(conn, ~p"/sources/#{source.id}/force_download") + conn = post(conn, ~p"/sources/#{source.id}/force_download_pending") + assert redirected_to(conn) == ~p"/sources/#{source.id}" + end + end + + describe "force_redownload" do + test "enqueues re-download tasks", %{conn: conn} do + source = source_fixture() + _media_item = media_item_fixture(source_id: source.id, media_downloaded_at: now()) + + assert [] = all_enqueued(worker: MediaDownloadWorker) + post(conn, ~p"/sources/#{source.id}/force_redownload") + assert [_] = all_enqueued(worker: MediaDownloadWorker) + end + + test "redirects to the source page", %{conn: conn} do + source = source_fixture() + + conn = post(conn, ~p"/sources/#{source.id}/force_redownload") assert redirected_to(conn) == ~p"/sources/#{source.id}" end end