From e0eb226abec309a1ed42329516dac066e5648df4 Mon Sep 17 00:00:00 2001 From: Luna D Date: Mon, 29 May 2023 13:06:41 +0200 Subject: [PATCH] fix source url display, provide all source urls --- lib/philomena/polymorphic.ex | 4 ++-- .../controllers/activity_controller.ex | 16 ++++++++-------- .../api/json/image/featured_controller.ex | 2 +- .../controllers/api/json/image_controller.ex | 2 +- .../controllers/api/json/oembed_controller.ex | 2 +- .../api/json/search/image_controller.ex | 2 +- .../controllers/api/rss/watched_controller.ex | 2 +- .../controllers/comment_controller.ex | 2 +- .../controllers/commission_controller.ex | 2 +- .../source_change_controller.ex | 2 +- .../fingerprint_profile/tag_change_controller.ex | 2 +- .../controllers/gallery_controller.ex | 12 +++++++----- .../image/comment/report_controller.ex | 2 +- .../controllers/image/comment_controller.ex | 2 +- .../controllers/image/description_controller.ex | 2 +- .../controllers/image/fave_controller.ex | 2 +- .../controllers/image/related_controller.ex | 4 ++-- .../controllers/image/report_controller.ex | 2 +- .../controllers/image/reporting_controller.ex | 6 +++--- .../image/source_change_controller.ex | 2 +- .../controllers/image/tag_change_controller.ex | 2 +- .../controllers/image/tag_controller.ex | 6 +++--- .../controllers/image/vote_controller.ex | 2 +- .../controllers/image_controller.ex | 2 +- .../ip_profile/source_change_controller.ex | 2 +- .../ip_profile/tag_change_controller.ex | 2 +- .../profile/commission/item_controller.ex | 4 ++-- .../profile/commission/report_controller.ex | 4 ++-- .../controllers/profile/commission_controller.ex | 4 ++-- .../profile/source_change_controller.ex | 2 +- .../controllers/profile/tag_change_controller.ex | 2 +- .../controllers/profile_controller.ex | 15 +++++++++------ .../controllers/search_controller.ex | 7 ++++++- .../controllers/tag/tag_change_controller.ex | 2 +- lib/philomena_web/controllers/tag_controller.ex | 2 +- lib/philomena_web/image_reverse.ex | 2 +- lib/philomena_web/markdown_renderer.ex | 2 +- .../templates/image/_options.html.slime | 2 +- .../templates/layout/_opengraph.html.slime | 4 ++-- .../templates/search/reverse/index.html.slime | 4 ++-- lib/philomena_web/views/api/json/image_view.ex | 4 +++- lib/philomena_web/views/api/json/oembed_view.ex | 2 +- lib/philomena_web/views/app_view.ex | 6 ++++++ lib/philomena_web/views/image_view.ex | 4 +++- 44 files changed, 90 insertions(+), 70 deletions(-) diff --git a/lib/philomena/polymorphic.ex b/lib/philomena/polymorphic.ex index dce694d5..0d9de092 100644 --- a/lib/philomena/polymorphic.ex +++ b/lib/philomena/polymorphic.ex @@ -20,12 +20,12 @@ defmodule Philomena.Polymorphic do } @preloads %{ - "Comment" => [:user, image: [tags: :aliases]], + "Comment" => [:user, image: [:sources, tags: :aliases]], "Commission" => [:user], "Conversation" => [:from, :to], "DnpEntry" => [:requesting_user, :tag], "Gallery" => [:creator], - "Image" => [:user, tags: :aliases], + "Image" => [:user, :sources, tags: :aliases], "Post" => [:user, topic: :forum], "Topic" => [:forum, :user], "Report" => [:user] diff --git a/lib/philomena_web/controllers/activity_controller.ex b/lib/philomena_web/controllers/activity_controller.ex index 6cc3ddf6..9c7dc7ec 100644 --- a/lib/philomena_web/controllers/activity_controller.ex +++ b/lib/philomena_web/controllers/activity_controller.ex @@ -77,7 +77,7 @@ defmodule PhilomenaWeb.ActivityController do |> filter_hidden(user, conn.params["hidden"]) |> order_by([i, f], desc: f.created_at) |> limit(1) - |> preload(tags: :aliases) + |> preload([:sources, tags: :aliases]) |> Repo.one() streams = @@ -147,9 +147,9 @@ defmodule PhilomenaWeb.ActivityController do Elasticsearch.msearch_records( [images, top_scoring, comments], [ - preload(Image, tags: :aliases), - preload(Image, tags: :aliases), - preload(Comment, [:user, image: [tags: :aliases]]) + preload(Image, [:sources, tags: :aliases]), + preload(Image, [:sources, tags: :aliases]), + preload(Comment, [:user, image: [:sources, tags: :aliases]]) ] ) @@ -160,10 +160,10 @@ defmodule PhilomenaWeb.ActivityController do Elasticsearch.msearch_records( [images, top_scoring, comments, watched], [ - preload(Image, tags: :aliases), - preload(Image, tags: :aliases), - preload(Comment, [:user, image: [tags: :aliases]]), - preload(Image, tags: :aliases) + preload(Image, [:sources, tags: :aliases]), + preload(Image, [:sources, tags: :aliases]), + preload(Comment, [:user, image: [:sources, tags: :aliases]]), + preload(Image, [:sources, tags: :aliases]) ] ) end diff --git a/lib/philomena_web/controllers/api/json/image/featured_controller.ex b/lib/philomena_web/controllers/api/json/image/featured_controller.ex index 6a2c5909..686dbe75 100644 --- a/lib/philomena_web/controllers/api/json/image/featured_controller.ex +++ b/lib/philomena_web/controllers/api/json/image/featured_controller.ex @@ -16,7 +16,7 @@ defmodule PhilomenaWeb.Api.Json.Image.FeaturedController do |> where([i], i.hidden_from_users == false) |> order_by([_i, f], desc: f.created_at) |> limit(1) - |> preload([:user, :intensity, tags: :aliases]) + |> preload([:user, :intensity, :sources, tags: :aliases]) |> Repo.one() case featured_image do diff --git a/lib/philomena_web/controllers/api/json/image_controller.ex b/lib/philomena_web/controllers/api/json/image_controller.ex index 3e5f17f5..a142aeb4 100644 --- a/lib/philomena_web/controllers/api/json/image_controller.ex +++ b/lib/philomena_web/controllers/api/json/image_controller.ex @@ -20,7 +20,7 @@ defmodule PhilomenaWeb.Api.Json.ImageController do image = Image |> where(id: ^id) - |> preload([:user, :intensity, tags: :aliases]) + |> preload([:user, :intensity, :sources, tags: :aliases]) |> Repo.one() case image do diff --git a/lib/philomena_web/controllers/api/json/oembed_controller.ex b/lib/philomena_web/controllers/api/json/oembed_controller.ex index 88486410..9c812708 100644 --- a/lib/philomena_web/controllers/api/json/oembed_controller.ex +++ b/lib/philomena_web/controllers/api/json/oembed_controller.ex @@ -37,7 +37,7 @@ defmodule PhilomenaWeb.Api.Json.OembedController do defp load_image(id) do Image |> where(id: ^id, hidden_from_users: false) - |> preload([:user, tags: :aliases]) + |> preload([:user, :sources, tags: :aliases]) |> Repo.one() end diff --git a/lib/philomena_web/controllers/api/json/search/image_controller.ex b/lib/philomena_web/controllers/api/json/search/image_controller.ex index 9338dc80..b410dedc 100644 --- a/lib/philomena_web/controllers/api/json/search/image_controller.ex +++ b/lib/philomena_web/controllers/api/json/search/image_controller.ex @@ -8,7 +8,7 @@ defmodule PhilomenaWeb.Api.Json.Search.ImageController do import Ecto.Query def index(conn, params) do - queryable = Image |> preload([:user, :intensity, tags: :aliases]) + queryable = Image |> preload([:user, :intensity, :sources, tags: :aliases]) user = conn.assigns.current_user case ImageLoader.search_string(conn, params["q"]) do diff --git a/lib/philomena_web/controllers/api/rss/watched_controller.ex b/lib/philomena_web/controllers/api/rss/watched_controller.ex index 6dbd84a4..ba38218e 100644 --- a/lib/philomena_web/controllers/api/rss/watched_controller.ex +++ b/lib/philomena_web/controllers/api/rss/watched_controller.ex @@ -9,7 +9,7 @@ defmodule PhilomenaWeb.Api.Rss.WatchedController do def index(conn, _params) do {:ok, {images, _tags}} = ImageLoader.search_string(conn, "my:watched") - images = Elasticsearch.search_records(images, preload(Image, tags: :aliases)) + images = Elasticsearch.search_records(images, preload(Image, [:sources, tags: :aliases])) # NB: this is RSS, but using the RSS format causes Phoenix not to # escape HTML diff --git a/lib/philomena_web/controllers/comment_controller.ex b/lib/philomena_web/controllers/comment_controller.ex index 6a5d434f..ad802c07 100644 --- a/lib/philomena_web/controllers/comment_controller.ex +++ b/lib/philomena_web/controllers/comment_controller.ex @@ -36,7 +36,7 @@ defmodule PhilomenaWeb.CommentController do conn.assigns.pagination ) |> Elasticsearch.search_records( - preload(Comment, [:deleted_by, image: [tags: :aliases], user: [awards: :badge]]) + preload(Comment, [:deleted_by, image: [:sources, tags: :aliases], user: [awards: :badge]]) ) rendered = MarkdownRenderer.render_collection(comments.entries, conn) diff --git a/lib/philomena_web/controllers/commission_controller.ex b/lib/philomena_web/controllers/commission_controller.ex index 4250a661..776c8e48 100644 --- a/lib/philomena_web/controllers/commission_controller.ex +++ b/lib/philomena_web/controllers/commission_controller.ex @@ -74,7 +74,7 @@ defmodule PhilomenaWeb.CommissionController do where: ui.updated_at >= ago(2, "week"), group_by: c.id, order_by: [asc: fragment("random()")], - preload: [user: [awards: :badge], items: [example_image: [tags: :aliases]]] + preload: [user: [awards: :badge], items: [example_image: [:sources, tags: :aliases]]] end defp presence(nil), diff --git a/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex b/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex index 84b057ec..f6772cd9 100644 --- a/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex +++ b/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do SourceChange |> where(fingerprint: ^fingerprint) |> order_by(desc: :id) - |> preload([:user, image: [:user, tags: :aliases]]) + |> preload([:user, image: [:user, :sources, tags: :aliases]]) |> Repo.paginate(conn.assigns.scrivener) render(conn, "index.html", diff --git a/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex b/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex index ebd1f586..56308aab 100644 --- a/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex +++ b/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.FingerprintProfile.TagChangeController do TagChange |> where(fingerprint: ^fingerprint) |> added_filter(params) - |> preload([:tag, :user, image: [:user, tags: :aliases]]) + |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/gallery_controller.ex b/lib/philomena_web/controllers/gallery_controller.ex index c526a0ca..ee19d230 100644 --- a/lib/philomena_web/controllers/gallery_controller.ex +++ b/lib/philomena_web/controllers/gallery_controller.ex @@ -16,7 +16,7 @@ defmodule PhilomenaWeb.GalleryController do plug :load_and_authorize_resource, model: Gallery, except: [:index], - preload: [:creator, thumbnail: [tags: :aliases]] + preload: [:creator, thumbnail: [:sources, tags: :aliases]] def index(conn, params) do galleries = @@ -32,7 +32,9 @@ defmodule PhilomenaWeb.GalleryController do }, conn.assigns.pagination ) - |> Elasticsearch.search_records(preload(Gallery, [:creator, thumbnail: [tags: :aliases]])) + |> Elasticsearch.search_records( + preload(Gallery, [:creator, thumbnail: [:sources, tags: :aliases]]) + ) render(conn, "index.html", title: "Galleries", @@ -63,9 +65,9 @@ defmodule PhilomenaWeb.GalleryController do Elasticsearch.msearch_records_with_hits( [images, gallery_prev, gallery_next], [ - preload(Image, tags: :aliases), - preload(Image, tags: :aliases), - preload(Image, tags: :aliases) + preload(Image, [:sources, tags: :aliases]), + preload(Image, [:sources, tags: :aliases]), + preload(Image, [:sources, tags: :aliases]) ] ) diff --git a/lib/philomena_web/controllers/image/comment/report_controller.ex b/lib/philomena_web/controllers/image/comment/report_controller.ex index 58014da3..27725a4b 100644 --- a/lib/philomena_web/controllers/image/comment/report_controller.ex +++ b/lib/philomena_web/controllers/image/comment/report_controller.ex @@ -18,7 +18,7 @@ defmodule PhilomenaWeb.Image.Comment.ReportController do model: Image, id_name: "image_id", persisted: true, - preload: [tags: :aliases] + preload: [:sources, tags: :aliases] plug PhilomenaWeb.LoadCommentPlug diff --git a/lib/philomena_web/controllers/image/comment_controller.ex b/lib/philomena_web/controllers/image/comment_controller.ex index 1c97ad1f..cfcda777 100644 --- a/lib/philomena_web/controllers/image/comment_controller.ex +++ b/lib/philomena_web/controllers/image/comment_controller.ex @@ -24,7 +24,7 @@ defmodule PhilomenaWeb.Image.CommentController do model: Image, id_name: "image_id", persisted: true, - preload: [tags: :aliases] + preload: [:sources, tags: :aliases] plug :verify_authorized when action in [:show] plug PhilomenaWeb.FilterForcedUsersPlug when action in [:create, :edit, :update] diff --git a/lib/philomena_web/controllers/image/description_controller.ex b/lib/philomena_web/controllers/image/description_controller.ex index 0d7f3442..903eb283 100644 --- a/lib/philomena_web/controllers/image/description_controller.ex +++ b/lib/philomena_web/controllers/image/description_controller.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do model: Image, id_name: "image_id", persisted: true, - preload: [:user, tags: :aliases] + preload: [:user, :sources, tags: :aliases] def update(conn, %{"image" => image_params}) do image = conn.assigns.image diff --git a/lib/philomena_web/controllers/image/fave_controller.ex b/lib/philomena_web/controllers/image/fave_controller.ex index 82e01861..2a546fac 100644 --- a/lib/philomena_web/controllers/image/fave_controller.ex +++ b/lib/philomena_web/controllers/image/fave_controller.ex @@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.FaveController do model: Image, id_name: "image_id", persisted: true, - preload: [tags: :aliases] + preload: [:sources, tags: :aliases] plug PhilomenaWeb.FilterForcedUsersPlug diff --git a/lib/philomena_web/controllers/image/related_controller.ex b/lib/philomena_web/controllers/image/related_controller.ex index 0928fd45..2abcbe6b 100644 --- a/lib/philomena_web/controllers/image/related_controller.ex +++ b/lib/philomena_web/controllers/image/related_controller.ex @@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.RelatedController do model: Image, id_name: "image_id", persisted: true, - preload: [:faves, tags: :aliases] + preload: [:faves, :sources, tags: :aliases] def index(conn, _params) do image = conn.assigns.image @@ -60,7 +60,7 @@ defmodule PhilomenaWeb.Image.RelatedController do pagination: %{conn.assigns.image_pagination | page_number: 1} ) - images = Elasticsearch.search_records(images, preload(Image, tags: :aliases)) + images = Elasticsearch.search_records(images, preload(Image, [:sources, tags: :aliases])) interactions = Interactions.user_interactions(images, user) diff --git a/lib/philomena_web/controllers/image/report_controller.ex b/lib/philomena_web/controllers/image/report_controller.ex index 06d084e0..99e2bace 100644 --- a/lib/philomena_web/controllers/image/report_controller.ex +++ b/lib/philomena_web/controllers/image/report_controller.ex @@ -17,7 +17,7 @@ defmodule PhilomenaWeb.Image.ReportController do model: Image, id_name: "image_id", persisted: true, - preload: [tags: :aliases] + preload: [:sources, tags: :aliases] def new(conn, _params) do image = conn.assigns.image diff --git a/lib/philomena_web/controllers/image/reporting_controller.ex b/lib/philomena_web/controllers/image/reporting_controller.ex index 1968e962..e03191c0 100644 --- a/lib/philomena_web/controllers/image/reporting_controller.ex +++ b/lib/philomena_web/controllers/image/reporting_controller.ex @@ -11,7 +11,7 @@ defmodule PhilomenaWeb.Image.ReportingController do model: Image, id_name: "image_id", persisted: true, - preload: [tags: :aliases] + preload: [:sources, tags: :aliases] def show(conn, _params) do image = conn.assigns.image @@ -21,8 +21,8 @@ defmodule PhilomenaWeb.Image.ReportingController do |> preload([ :user, :modifier, - image: [:user, tags: :aliases], - duplicate_of_image: [:user, tags: :aliases] + image: [:user, :sources, tags: :aliases], + duplicate_of_image: [:user, :sources, tags: :aliases] ]) |> where([d], d.image_id == ^image.id or d.duplicate_of_image_id == ^image.id) |> Repo.all() diff --git a/lib/philomena_web/controllers/image/source_change_controller.ex b/lib/philomena_web/controllers/image/source_change_controller.ex index 6f82e55d..9d3531e9 100644 --- a/lib/philomena_web/controllers/image/source_change_controller.ex +++ b/lib/philomena_web/controllers/image/source_change_controller.ex @@ -15,7 +15,7 @@ defmodule PhilomenaWeb.Image.SourceChangeController do source_changes = SourceChange |> where(image_id: ^image.id) - |> preload([:user, image: [:user, tags: :aliases]]) + |> preload([:user, image: [:user, :sources, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/image/tag_change_controller.ex b/lib/philomena_web/controllers/image/tag_change_controller.ex index 4938f96a..6868ed96 100644 --- a/lib/philomena_web/controllers/image/tag_change_controller.ex +++ b/lib/philomena_web/controllers/image/tag_change_controller.ex @@ -23,7 +23,7 @@ defmodule PhilomenaWeb.Image.TagChangeController do TagChange |> where(image_id: ^image.id) |> added_filter(params) - |> preload([:tag, :user, image: [:user, tags: :aliases]]) + |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/image/tag_controller.ex b/lib/philomena_web/controllers/image/tag_controller.ex index a13c11ac..2bae9731 100644 --- a/lib/philomena_web/controllers/image/tag_controller.ex +++ b/lib/philomena_web/controllers/image/tag_controller.ex @@ -23,7 +23,7 @@ defmodule PhilomenaWeb.Image.TagController do plug :load_and_authorize_resource, model: Image, id_name: "image_id", - preload: [:user, :locked_tags, tags: :aliases] + preload: [:user, :locked_tags, :sources, tags: :aliases] def update(conn, %{"image" => image_params}) do attributes = conn.assigns.attributes @@ -62,7 +62,7 @@ defmodule PhilomenaWeb.Image.TagController do image = image - |> Repo.preload([tags: :aliases], force: true) + |> Repo.preload([:sources, tags: :aliases], force: true) changeset = Images.change_image(image) @@ -78,7 +78,7 @@ defmodule PhilomenaWeb.Image.TagController do {:error, :image, changeset, _} -> image = image - |> Repo.preload([tags: :aliases], force: true) + |> Repo.preload([:sources, tags: :aliases], force: true) conn |> put_view(PhilomenaWeb.ImageView) diff --git a/lib/philomena_web/controllers/image/vote_controller.ex b/lib/philomena_web/controllers/image/vote_controller.ex index cf5dfdbc..d7fbed53 100644 --- a/lib/philomena_web/controllers/image/vote_controller.ex +++ b/lib/philomena_web/controllers/image/vote_controller.ex @@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.VoteController do model: Image, id_name: "image_id", persisted: true, - preload: [tags: :aliases] + preload: [:sources, tags: :aliases] plug PhilomenaWeb.FilterForcedUsersPlug diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index 122d49e2..47e9e088 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -40,7 +40,7 @@ defmodule PhilomenaWeb.ImageController do {:ok, {images, _tags}} = ImageLoader.search_string(conn, "created_at.lte:3 minutes ago, -thumbnails_generated:false") - images = Elasticsearch.search_records(images, preload(Image, tags: :aliases)) + images = Elasticsearch.search_records(images, preload(Image, [:sources, tags: :aliases])) interactions = Interactions.user_interactions(images, conn.assigns.current_user) diff --git a/lib/philomena_web/controllers/ip_profile/source_change_controller.ex b/lib/philomena_web/controllers/ip_profile/source_change_controller.ex index 7e057de2..f5bf868c 100644 --- a/lib/philomena_web/controllers/ip_profile/source_change_controller.ex +++ b/lib/philomena_web/controllers/ip_profile/source_change_controller.ex @@ -14,7 +14,7 @@ defmodule PhilomenaWeb.IpProfile.SourceChangeController do SourceChange |> where(ip: ^ip) |> order_by(desc: :id) - |> preload([:user, image: [:user, tags: :aliases]]) + |> preload([:user, image: [:user, :sources, tags: :aliases]]) |> Repo.paginate(conn.assigns.scrivener) render(conn, "index.html", diff --git a/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex b/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex index 7ba3a260..b9779913 100644 --- a/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex +++ b/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex @@ -14,7 +14,7 @@ defmodule PhilomenaWeb.IpProfile.TagChangeController do TagChange |> where(ip: ^ip) |> added_filter(params) - |> preload([:tag, :user, image: [:user, tags: :aliases]]) + |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/profile/commission/item_controller.ex b/lib/philomena_web/controllers/profile/commission/item_controller.ex index 3502131d..90699b08 100644 --- a/lib/philomena_web/controllers/profile/commission/item_controller.ex +++ b/lib/philomena_web/controllers/profile/commission/item_controller.ex @@ -15,9 +15,9 @@ defmodule PhilomenaWeb.Profile.Commission.ItemController do preload: [ :verified_links, commission: [ - sheet_image: [tags: :aliases], + sheet_image: [:sources, tags: :aliases], user: [awards: :badge], - items: [example_image: [tags: :aliases]] + items: [example_image: [:sources, tags: :aliases]] ] ], persisted: true diff --git a/lib/philomena_web/controllers/profile/commission/report_controller.ex b/lib/philomena_web/controllers/profile/commission/report_controller.ex index 181e0410..9c9d7ac2 100644 --- a/lib/philomena_web/controllers/profile/commission/report_controller.ex +++ b/lib/philomena_web/controllers/profile/commission/report_controller.ex @@ -20,9 +20,9 @@ defmodule PhilomenaWeb.Profile.Commission.ReportController do preload: [ :verified_links, commission: [ - sheet_image: [tags: :aliases], + sheet_image: [:sources, tags: :aliases], user: [awards: :badge], - items: [example_image: [tags: :aliases]] + items: [example_image: [:sources, tags: :aliases]] ] ], persisted: true diff --git a/lib/philomena_web/controllers/profile/commission_controller.ex b/lib/philomena_web/controllers/profile/commission_controller.ex index 20590279..f934fc4d 100644 --- a/lib/philomena_web/controllers/profile/commission_controller.ex +++ b/lib/philomena_web/controllers/profile/commission_controller.ex @@ -15,9 +15,9 @@ defmodule PhilomenaWeb.Profile.CommissionController do preload: [ :verified_links, commission: [ - sheet_image: [tags: :aliases], + sheet_image: [:sources, tags: :aliases], user: [awards: :badge], - items: [example_image: [tags: :aliases]] + items: [example_image: [:sources, tags: :aliases]] ] ], persisted: true diff --git a/lib/philomena_web/controllers/profile/source_change_controller.ex b/lib/philomena_web/controllers/profile/source_change_controller.ex index 9a0fb595..f0051f71 100644 --- a/lib/philomena_web/controllers/profile/source_change_controller.ex +++ b/lib/philomena_web/controllers/profile/source_change_controller.ex @@ -25,7 +25,7 @@ defmodule PhilomenaWeb.Profile.SourceChangeController do [sc, i], sc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true) ) - |> preload([:user, image: [:user, tags: :aliases]]) + |> preload([:user, image: [:user, :sources, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/profile/tag_change_controller.ex b/lib/philomena_web/controllers/profile/tag_change_controller.ex index 0c58adc4..358990e6 100644 --- a/lib/philomena_web/controllers/profile/tag_change_controller.ex +++ b/lib/philomena_web/controllers/profile/tag_change_controller.ex @@ -21,7 +21,7 @@ defmodule PhilomenaWeb.Profile.TagChangeController do tc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true) ) |> added_filter(params) - |> preload([:tag, :user, image: [:user, tags: :aliases]]) + |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/profile_controller.ex b/lib/philomena_web/controllers/profile_controller.ex index 5f9d00fa..c91ea8d2 100644 --- a/lib/philomena_web/controllers/profile_controller.ex +++ b/lib/philomena_web/controllers/profile_controller.ex @@ -28,7 +28,10 @@ defmodule PhilomenaWeb.ProfileController do awards: [:badge, :awarded_by], public_links: :tag, verified_links: :tag, - commission: [sheet_image: [tags: :aliases], items: [example_image: [tags: :aliases]]] + commission: [ + sheet_image: [:sources, tags: :aliases], + items: [example_image: [:sources, tags: :aliases]] + ] ] plug :set_admin_metadata @@ -119,10 +122,10 @@ defmodule PhilomenaWeb.ProfileController do Elasticsearch.msearch_records( [recent_uploads, recent_faves, recent_artwork, recent_comments, recent_posts], [ - preload(Image, tags: :aliases), - preload(Image, tags: :aliases), - preload(Image, tags: :aliases), - preload(Comment, user: [awards: :badge], image: [tags: :aliases]), + preload(Image, [:sources, tags: :aliases]), + preload(Image, [:sources, tags: :aliases]), + preload(Image, [:sources, tags: :aliases]), + preload(Comment, user: [awards: :badge], image: [:sources, tags: :aliases]), preload(Post, user: [awards: :badge], topic: :forum) ] ) @@ -144,7 +147,7 @@ defmodule PhilomenaWeb.ProfileController do recent_galleries = Gallery |> where(creator_id: ^user.id) - |> preload([:creator, thumbnail: [tags: :aliases]]) + |> preload([:creator, thumbnail: [:sources, tags: :aliases]]) |> limit(4) |> Repo.all() diff --git a/lib/philomena_web/controllers/search_controller.ex b/lib/philomena_web/controllers/search_controller.ex index 2bfbc7f9..9b6974e4 100644 --- a/lib/philomena_web/controllers/search_controller.ex +++ b/lib/philomena_web/controllers/search_controller.ex @@ -12,7 +12,12 @@ defmodule PhilomenaWeb.SearchController do case ImageLoader.search_string(conn, params["q"]) do {:ok, {images, tags}} -> - images = search_function(custom_ordering?(conn)).(images, preload(Image, tags: :aliases)) + images = + search_function(custom_ordering?(conn)).( + images, + preload(Image, [:sources, tags: :aliases]) + ) + interactions = Interactions.user_interactions(images, user) conn diff --git a/lib/philomena_web/controllers/tag/tag_change_controller.ex b/lib/philomena_web/controllers/tag/tag_change_controller.ex index 69adcc2e..650a2569 100644 --- a/lib/philomena_web/controllers/tag/tag_change_controller.ex +++ b/lib/philomena_web/controllers/tag/tag_change_controller.ex @@ -16,7 +16,7 @@ defmodule PhilomenaWeb.Tag.TagChangeController do TagChange |> where(tag_id: ^tag.id) |> added_filter(params) - |> preload([:tag, :user, image: [:user, tags: :aliases]]) + |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/tag_controller.ex b/lib/philomena_web/controllers/tag_controller.ex index 766508ae..46eb95b7 100644 --- a/lib/philomena_web/controllers/tag_controller.ex +++ b/lib/philomena_web/controllers/tag_controller.ex @@ -57,7 +57,7 @@ defmodule PhilomenaWeb.TagController do {images, _tags} = ImageLoader.query(conn, %{term: %{"namespaced_tags.name" => tag.name}}) - images = Elasticsearch.search_records(images, preload(Image, tags: :aliases)) + images = Elasticsearch.search_records(images, preload(Image, [:sources, tags: :aliases])) interactions = Interactions.user_interactions(images, user) diff --git a/lib/philomena_web/image_reverse.ex b/lib/philomena_web/image_reverse.ex index 02dc9d59..e1d78a50 100644 --- a/lib/philomena_web/image_reverse.ex +++ b/lib/philomena_web/image_reverse.ex @@ -20,7 +20,7 @@ defmodule PhilomenaWeb.ImageReverse do dist = normalize_dist(image_params) DuplicateReports.duplicates_of(intensities, aspect, dist, dist) - |> preload([:user, :intensity, [tags: :aliases]]) + |> preload([:user, :intensity, [:sources, tags: :aliases]]) |> Repo.all() end end diff --git a/lib/philomena_web/markdown_renderer.ex b/lib/philomena_web/markdown_renderer.ex index 8e96982c..16d926ea 100644 --- a/lib/philomena_web/markdown_renderer.ex +++ b/lib/philomena_web/markdown_renderer.ex @@ -45,7 +45,7 @@ defmodule PhilomenaWeb.MarkdownRenderer do Image |> where([i], i.id in ^ids) - |> preload(tags: :aliases) + |> preload([:sources, tags: :aliases]) |> Repo.all() |> Map.new(&{&1.id, &1}) end diff --git a/lib/philomena_web/templates/image/_options.html.slime b/lib/philomena_web/templates/image/_options.html.slime index be26ec4a..f1514292 100644 --- a/lib/philomena_web/templates/image/_options.html.slime +++ b/lib/philomena_web/templates/image/_options.html.slime @@ -28,7 +28,7 @@ p Loading... .block__tab.hidden data-tab="sharing" #embed_options - - source_link = if @image.source_url in [nil, ""], do: " (Original source unknown at time of posting)", else: " - [url=#{@image.source_url}]Original source[/url]" + - source_link = if image_has_sources(@image), do: " - [url=#{image_first_source(@image)}]Original source[/url]", else: " (Original source unknown at time of posting)" h5 Derpibooru p strong> Small thumbnail diff --git a/lib/philomena_web/templates/layout/_opengraph.html.slime b/lib/philomena_web/templates/layout/_opengraph.html.slime index 70d09b72..30ae6555 100644 --- a/lib/philomena_web/templates/layout/_opengraph.html.slime +++ b/lib/philomena_web/templates/layout/_opengraph.html.slime @@ -17,8 +17,8 @@ meta name="format-detection" content="telephone=no" = for tag <- artist_tags(image.tags) do meta property="dc:creator" content=tag.name_in_namespace - = if image.source_url not in [nil, ""] do - meta property="foaf:primaryTopic" content=image.source_url + = if image_has_sources(image) do + meta property="foaf:primaryTopic" content=image_first_source(image) link rel="alternate" type="application/json+oembed" href=Routes.api_json_oembed_url(@conn, :index, url: Routes.image_path(@conn, :show, image)) title="oEmbed JSON Profile" diff --git a/lib/philomena_web/templates/search/reverse/index.html.slime b/lib/philomena_web/templates/search/reverse/index.html.slime index 3a5c14c1..a4c24e01 100644 --- a/lib/philomena_web/templates/search/reverse/index.html.slime +++ b/lib/philomena_web/templates/search/reverse/index.html.slime @@ -48,9 +48,9 @@ h1 Reverse Search th h3 = link "##{match.id}", to: Routes.image_path(@conn, :show, match) p - = if match.source_url not in [nil, ""] do + = if image_has_sources(match) do span.source_url - = link "Source", to: match.source_url + = link "Source", to: image_first_source(match) - else ' Unknown source diff --git a/lib/philomena_web/views/api/json/image_view.ex b/lib/philomena_web/views/api/json/image_view.ex index abfc347e..924ae86b 100644 --- a/lib/philomena_web/views/api/json/image_view.ex +++ b/lib/philomena_web/views/api/json/image_view.ex @@ -80,7 +80,9 @@ defmodule PhilomenaWeb.Api.Json.ImageView do comment_count: image.comments_count, tag_count: length(image.tags), description: image.description, - source_url: image.source_url, + source_url: + if(Enum.count(image.sources) > 0, do: Enum.at(image.sources, 0).source, else: ""), + source_urls: Enum.map(image.sources, & &1.source), view_url: ImageView.pretty_url(image, false, false), representations: ImageView.thumb_urls(image, false), thumbnails_generated: image.thumbnails_generated, diff --git a/lib/philomena_web/views/api/json/oembed_view.ex b/lib/philomena_web/views/api/json/oembed_view.ex index 1ca62784..19501e40 100644 --- a/lib/philomena_web/views/api/json/oembed_view.ex +++ b/lib/philomena_web/views/api/json/oembed_view.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.Api.Json.OembedView do version: "1.0", type: "photo", title: "##{image.id} - #{tag_list(image)} - Derpibooru", - author_url: image.source_url || "", + author_url: image_first_source(image), author_name: artist_tags(image.tags), provider_name: "Derpibooru", provider_url: PhilomenaWeb.Endpoint.url(), diff --git a/lib/philomena_web/views/app_view.ex b/lib/philomena_web/views/app_view.ex index 5c36140a..1b0febd5 100644 --- a/lib/philomena_web/views/app_view.ex +++ b/lib/philomena_web/views/app_view.ex @@ -241,6 +241,12 @@ defmodule PhilomenaWeb.AppView do ] end + def image_has_sources(image), do: Enum.count(image.sources) > 0 + + def image_first_source(image) do + if image_has_sources(image), do: Enum.at(image.sources, 0).source, else: "" + end + def get_flash(%{assigns: %{flash: nil}}), do: %{} def get_flash(%{assigns: %{flash: flash}}), do: flash def get_flash(_), do: %{} diff --git a/lib/philomena_web/views/image_view.ex b/lib/philomena_web/views/image_view.ex index 006c7aec..30accb8b 100644 --- a/lib/philomena_web/views/image_view.ex +++ b/lib/philomena_web/views/image_view.ex @@ -162,7 +162,9 @@ defmodule PhilomenaWeb.ImageView do downvotes: image.downvotes_count, comment_count: image.comments_count, created_at: DateTime.to_iso8601(image.created_at), - source_url: image.source_url, + source_url: + if(Enum.count(image.sources) > 0, do: Enum.at(image.sources, 0).source, else: ""), + source_urls: Jason.encode!(Enum.map(image.sources, & &1.source)), uris: Jason.encode!(thumb_urls(image, can?(conn, :show, image))), width: image.image_width, height: image.image_height,