From ebf5d6afb5b6935c542330b21a74d23643068130 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Mon, 22 Apr 2024 09:08:51 -0700 Subject: [PATCH] [WIP] --- .../controllers/sources/source_controller.ex | 25 +++++++++++++++++++ .../controllers/sources/source_html.ex | 10 ++++++++ .../sources/source_html/show.html.heex | 17 +++++++++++++ lib/pinchflat_web/router.ex | 1 + 4 files changed, 53 insertions(+) diff --git a/lib/pinchflat_web/controllers/sources/source_controller.ex b/lib/pinchflat_web/controllers/sources/source_controller.ex index 8de11f2..97beccd 100644 --- a/lib/pinchflat_web/controllers/sources/source_controller.ex +++ b/lib/pinchflat_web/controllers/sources/source_controller.ex @@ -62,6 +62,31 @@ defmodule PinchflatWeb.Sources.SourceController do render(conn, :show, source: source, pending_tasks: pending_tasks) end + # TODO: test + # TODO: also do for media items + # TODO: check to see if I've lost the plot here + def show_image(conn, %{"source_id" => id, "image_type" => image_type}) do + source = Sources.get_source!(id) + + filepath = + case image_type do + "poster" -> source.poster_filepath + "fanart" -> source.fanart_filepath + "banner" -> source.banner_filepath + _ -> nil + end + + if filepath && File.exists?(filepath) do + conn + |> put_resp_content_type(MIME.from_path(filepath)) + |> send_file(200, filepath) + else + conn + |> put_status(404) + |> text("Image not found") + end + end + def edit(conn, %{"id" => id}) do source = Sources.get_source!(id) changeset = Sources.change_source(source) diff --git a/lib/pinchflat_web/controllers/sources/source_html.ex b/lib/pinchflat_web/controllers/sources/source_html.ex index ab1ef07..d2d00cd 100644 --- a/lib/pinchflat_web/controllers/sources/source_html.ex +++ b/lib/pinchflat_web/controllers/sources/source_html.ex @@ -25,6 +25,16 @@ defmodule PinchflatWeb.Sources.SourceHTML do ] end + def source_image_mapping(source) do + image_mapping = [ + {"Poster", source.poster_filepath, "poster"}, + {"Banner", source.banner_filepath, "banner"}, + {"Fanart", source.fanart_filepath, "fanart"} + ] + + Enum.filter(image_mapping, fn {_, filepath, _} -> filepath end) + end + def rss_feed_url(conn, source) do url(conn, ~p"/sources/#{source.uuid}/feed") <> ".xml" end diff --git a/lib/pinchflat_web/controllers/sources/source_html/show.html.heex b/lib/pinchflat_web/controllers/sources/source_html/show.html.heex index 2d110c4..f2f1e11 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/show.html.heex +++ b/lib/pinchflat_web/controllers/sources/source_html/show.html.heex @@ -36,6 +36,23 @@ <.list_items_from_map map={Map.from_struct(@source)} /> + <:tab title="Images"> +
+

Images

+ <%= if source_image_mapping(@source) == [] do %> +

Nothing Here!

+ <% else %> +
+
+ <%= name %> + + {name} + +
+
+ <% end %> +
+ <:tab title="Pending Media"> <%= live_render( @conn, diff --git a/lib/pinchflat_web/router.ex b/lib/pinchflat_web/router.ex index b04f840..766da3b 100644 --- a/lib/pinchflat_web/router.ex +++ b/lib/pinchflat_web/router.ex @@ -33,6 +33,7 @@ defmodule PinchflatWeb.Router do resources "/settings", Settings.SettingController, only: [:show, :update], singleton: true resources "/sources", Sources.SourceController do + get "/image/:image_type", Sources.SourceController, :show_image post "/force_download", Sources.SourceController, :force_download post "/force_index", Sources.SourceController, :force_index post "/force_metadata_refresh", Sources.SourceController, :force_metadata_refresh