diff --git a/assets/css/views/_images.scss b/assets/css/views/_images.scss index 0f9a0f44..a01e0f55 100644 --- a/assets/css/views/_images.scss +++ b/assets/css/views/_images.scss @@ -322,3 +322,16 @@ span.spoiler div.image-container { .full-height { height: 100%; } + +.image_sources { + display: grid; + grid-template-columns: 2em auto; +} + +.image_source__icon, .image_source__link { + padding: 0.5em; +} + +.image_source__icon { + justify-self: center; +} diff --git a/config/runtime.exs b/config/runtime.exs index d27b87c6..2c434e0b 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -28,6 +28,7 @@ config :philomena, badge_url_root: System.fetch_env!("BADGE_URL_ROOT"), mailer_address: System.fetch_env!("MAILER_ADDRESS"), tag_file_root: System.fetch_env!("TAG_FILE_ROOT"), + site_domains: System.fetch_env!("SITE_DOMAINS"), tag_url_root: System.fetch_env!("TAG_URL_ROOT"), redis_host: System.get_env("REDIS_HOST", "localhost"), proxy_host: System.get_env("PROXY_HOST"), diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index 2b2eddca..4383f509 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -342,12 +342,12 @@ defmodule Philomena.Images do |> Image.source_changeset(%{}, old_sources, new_sources) |> repo.update() |> case do - {:ok, image} -> - {:ok, {image, image.added_sources, image.removed_sources}} + {:ok, image} -> + {:ok, {image, image.added_sources, image.removed_sources}} - error -> - error - end + error -> + error + end end) |> Multi.run(:added_source_changes, fn repo, %{image: {image, added_sources, _removed}} -> source_changes = diff --git a/lib/philomena/images/source_differ.ex b/lib/philomena/images/source_differ.ex index 02843371..8ac29a08 100644 --- a/lib/philomena/images/source_differ.ex +++ b/lib/philomena/images/source_differ.ex @@ -59,7 +59,8 @@ defmodule Philomena.Images.SourceDiffer do [] end - _ -> [] + _ -> + [] end) end diff --git a/lib/philomena_web/controllers/duplicate_report_controller.ex b/lib/philomena_web/controllers/duplicate_report_controller.ex index bc87711b..f30539a0 100644 --- a/lib/philomena_web/controllers/duplicate_report_controller.ex +++ b/lib/philomena_web/controllers/duplicate_report_controller.ex @@ -29,8 +29,8 @@ defmodule PhilomenaWeb.DuplicateReportController 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] ]) |> order_by(desc: :created_at) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index fe194767..122d49e2 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.ImageController do Images.Source, Comments.Comment, Galleries.Gallery - } + } alias Philomena.Elasticsearch alias Philomena.Interactions diff --git a/lib/philomena_web/templates/image/_source.html.slime b/lib/philomena_web/templates/image/_source.html.slime index 97f37d42..20c4e3fc 100644 --- a/lib/philomena_web/templates/image/_source.html.slime +++ b/lib/philomena_web/templates/image/_source.html.slime @@ -46,16 +46,6 @@ ' Source: - else ' Sources: - - p - = if has_sources do - = for source <- @image.sources do - a.js-source-link href=source.source - strong= source.source - - - else - em> not provided yet - = if @source_change_count > 0 do a.button.button--link.button--separate-left href=Routes.image_source_change_path(@conn, :index, @image) title="Source history" i.fa.fa-history> @@ -68,3 +58,22 @@ button.button.button--state-danger.button--separate-left type="submit" data-confirm="Are you really, really sure?" title="Wipe sources" i.fas.fa-eraser> ' Wipe + .image_sources + = if has_sources do + - [first_source | sources] = @image.sources + .image_source__icon + i class=image_source_icon(first_source.source) + .image_source__link + a.js-source-link href=first_source.source + strong = first_source.source + = for source <- sources do + .image_source__icon + i class=image_source_icon(source.source) + .image_source__link + a href=source.source + strong = source.source + - else + .image_source__icon + i.fa.fa-unlink + .image_source__link + em> not provided yet diff --git a/lib/philomena_web/views/duplicate_report_view.ex b/lib/philomena_web/views/duplicate_report_view.ex index 34192974..f53b333f 100644 --- a/lib/philomena_web/views/duplicate_report_view.ex +++ b/lib/philomena_web/views/duplicate_report_view.ex @@ -58,19 +58,24 @@ defmodule PhilomenaWeb.DuplicateReportView do do: abs(duplicate_of_image.image_aspect_ratio - image.image_aspect_ratio) <= 0.009 def neither_have_source?(%{image: image, duplicate_of_image: duplicate_of_image}), - do: blank?(duplicate_of_image.source_url) and blank?(image.source_url) + do: Enum.empty?(duplicate_of_image.sources) and Enum.empty?(image.sources) - def same_source?(%{image: image, duplicate_of_image: duplicate_of_image}), - do: to_string(duplicate_of_image.source_url) == to_string(image.source_url) + def same_source?(%{image: image, duplicate_of_image: duplicate_of_image}) do + MapSet.equal?(MapSet.new(image.sources), MapSet.new(duplicate_of_image.sources)) + end - def similar_source?(%{image: image, duplicate_of_image: duplicate_of_image}), - do: uri_host(image.source_url) == uri_host(duplicate_of_image.source_url) + def similar_source?(%{image: image, duplicate_of_image: duplicate_of_image}) do + MapSet.equal?( + MapSet.new(image.sources, &URI.parse(&1.source).host), + MapSet.new(duplicate_of_image.sources, &URI.parse(&1.source).host) + ) + end def source_on_target?(%{image: image, duplicate_of_image: duplicate_of_image}), - do: present?(duplicate_of_image.source_url) and blank?(image.source_url) + do: Enum.any?(duplicate_of_image.sources) and Enum.empty?(image.sources) def source_on_source?(%{image: image, duplicate_of_image: duplicate_of_image}), - do: blank?(duplicate_of_image.source_url) && present?(image.source_url) + do: Enum.empty?(duplicate_of_image.sources) && Enum.any?(image.sources) def same_artist_tags?(%{image: image, duplicate_of_image: duplicate_of_image}), do: MapSet.equal?(artist_tags(image), artist_tags(duplicate_of_image)) diff --git a/lib/philomena_web/views/image_view.ex b/lib/philomena_web/views/image_view.ex index f6368458..4aaa70a8 100644 --- a/lib/philomena_web/views/image_view.ex +++ b/lib/philomena_web/views/image_view.ex @@ -287,4 +287,68 @@ defmodule PhilomenaWeb.ImageView do Philomena.Search.Evaluator.hits?(doc, query) end + + def image_source_icon(nil), do: "fa fa-link" + def image_source_icon(""), do: "fa fa-link" + + def image_source_icon(source) do + site_domains = + String.split(Application.get_env(:philomena, :site_domains), ",") ++ + Application.get_env(:philomena, :cdn_host) + + uri = URI.parse(source) + + case uri.host do + "twitter.com" -> + "fab fa-twitter" + + "www.twitter.com" -> + "fab fa-twitter" + + "pbs.twimg.com" -> + "fab fa-twitter" + + "twimg.com" -> + "fab fa-twitter" + + "deviantart.com" -> + "fab fa-deviantart" + + "www.deviantart.com" -> + "fab fa-deviantart" + + "sta.sh" -> + "fab fa-deviantart" + + "www.sta.sh" -> + "fab fa-deviantart" + + "cdn.discordapp.com" -> + "fab fa-discord" + + "discordapp.com" -> + "fab fa-discord" + + "discord.com" -> + "fab fa-discord" + + "derpibooru.org" -> + "fab fa-phoenix-framework" + + "www.derpibooru.org" -> + "fab fa-phoenix-framework" + + "trixiebooru.org" -> + "fab fa-phoenix-framework" + + "www.trixiebooru.org" -> + "fab fa-phoenix-framework" + + "derpicdn.net" -> + "fab fa-phoenix-framework" + + link -> + if Enum.member?(site_domains, link), do: "favicon-home", else: "fa fa-link" + end + end end diff --git a/priv/repo/migrations/20211009011024_rewrite_source_changes.exs b/priv/repo/migrations/20211009011024_rewrite_source_changes.exs index 52b3cfd4..b300af39 100644 --- a/priv/repo/migrations/20211009011024_rewrite_source_changes.exs +++ b/priv/repo/migrations/20211009011024_rewrite_source_changes.exs @@ -49,9 +49,7 @@ defmodule Philomena.Repo.Migrations.RewriteSourceChanges do check: "length(source) >= 8 and length(source) <= 1024" ) - create constraint(:image_sources, :image_sources_source_check, - check: "source ~* '^https?://'" - ) + create constraint(:image_sources, :image_sources_source_check, check: "source ~* '^https?://'") execute(""" insert into image_sources (image_id, source) @@ -122,9 +120,7 @@ defmodule Philomena.Repo.Migrations.RewriteSourceChanges do execute("truncate image_sources") - drop constraint(:image_sources, :image_sources_source_check, - check: "source ~* '^https?://'" - ) + drop constraint(:image_sources, :image_sources_source_check, check: "source ~* '^https?://'") create constraint(:image_sources, :length_must_be_valid, check: "length(source) >= 8 and length(source) <= 1024"