From e365f264ef32a31ab684d69b91e606ab2ce35295 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Sun, 24 Mar 2024 08:59:43 -0700 Subject: [PATCH] [WIP] more expanding on RSS --- lib/pinchflat/podcasts/rss_feed_builder.ex | 11 ++++++-- .../controllers/sources/source_controller.ex | 28 +++++++++++++++++++ lib/pinchflat_web/router.ex | 2 ++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/pinchflat/podcasts/rss_feed_builder.ex b/lib/pinchflat/podcasts/rss_feed_builder.ex index d7b041b..1c921ed 100644 --- a/lib/pinchflat/podcasts/rss_feed_builder.ex +++ b/lib/pinchflat/podcasts/rss_feed_builder.ex @@ -33,17 +33,17 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do #{Calendar.strftime(DateTime.utc_now(), @datetime_format)} #{Calendar.strftime(source.inserted_at, @datetime_format)} - false + yes #{source.uuid} - https://raw.githubusercontent.com/kieraneglin/pinchflat/master/priv/static/images/originals/logo.png + #{generate_source_image_path(source)} #{source.custom_name} #{source.original_url} #{source.custom_name} #{source.custom_name} yes - + false @@ -85,6 +85,11 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do "#{url_base()}/media/#{media_item.uuid}/stream#{extension}" end + # TODO: add extension maybe. maybe refactor controller to handle this + defp generate_source_image_path(source) do + "#{url_base()}/sources/#{source.uuid}/feed_image" + end + defp generate_upload_date(media_item) do media_item.upload_date |> Date.to_gregorian_days() diff --git a/lib/pinchflat_web/controllers/sources/source_controller.ex b/lib/pinchflat_web/controllers/sources/source_controller.ex index ae5b3f1..b67846f 100644 --- a/lib/pinchflat_web/controllers/sources/source_controller.ex +++ b/lib/pinchflat_web/controllers/sources/source_controller.ex @@ -59,6 +59,8 @@ defmodule PinchflatWeb.Sources.SourceController do ) end + # TODO: test + # TODO: maybe move both of these to a separate controller def feed(conn, %{"id" => uuid}) do # TODO: change this to UUID source = Repo.get_by!(Source, id: uuid) @@ -72,6 +74,32 @@ defmodule PinchflatWeb.Sources.SourceController do |> send_resp(200, xml) end + # TODO: test + # TODO: look into media_items having a thumbnail path when the image is embedded but not on disk + # TODO: pull these images from the internal metadata instead. this implies I'll have to hook up + # metadata images for sources + def feed_image(conn, %{"id" => uuid}) do + source = Repo.get_by!(Source, uuid: uuid) + media_item = Media.list_downloaded_media_items_for(source, limit: 1) + + filepath = + case {source.poster_filepath, media_item} do + {poster, _} when poster != nil -> poster + {nil, [media_item]} -> media_item.thumbnail_filepath + _ -> nil + end + + IO.inspect(filepath) + + if filepath && File.exists?(filepath) do + conn + |> put_resp_content_type(MIME.from_path(filepath)) + |> send_file(200, filepath) + else + send_resp(conn, 404, "File 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/router.ex b/lib/pinchflat_web/router.ex index c452b58..0a1071c 100644 --- a/lib/pinchflat_web/router.ex +++ b/lib/pinchflat_web/router.ex @@ -37,6 +37,8 @@ defmodule PinchflatWeb.Router do # so people that want RSS feeds to work can enable it. scope "/", PinchflatWeb do get "/sources/:id/feed", Sources.SourceController, :feed + get "/sources/:id/feed_image", Sources.SourceController, :feed_image + get "/media/:id/stream", MediaItems.MediaItemController, :stream end