diff --git a/assets/js/utils/dom.ts b/assets/js/utils/dom.ts index 06a1dd3e..77cdfea6 100644 --- a/assets/js/utils/dom.ts +++ b/assets/js/utils/dom.ts @@ -1,5 +1,7 @@ // DOM Utils +type PhilomenaInputElements = HTMLTextAreaElement | HTMLInputElement | HTMLButtonElement; + /** * Get the first matching element */ @@ -34,13 +36,13 @@ export function clearEl(...elements: E[] | ConcatArray }); } -export function disableEl(...elements: E[] | ConcatArray[]) { +export function disableEl(...elements: E[] | ConcatArray[]) { ([] as E[]).concat(...elements).forEach(el => { el.disabled = true; }); } -export function enableEl(...elements: E[] | ConcatArray[]) { +export function enableEl(...elements: E[] | ConcatArray[]) { ([] as E[]).concat(...elements).forEach(el => { el.disabled = false; }); diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index 4383f509..600f1a71 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -548,6 +548,13 @@ defmodule Philomena.Images do |> Multi.run(:copy_tags, fn _, %{} -> {:ok, Tags.copy_tags(image, duplicate_of_image)} end) + |> Multi.run(:migrate_sources, fn repo, %{} -> + {:ok, + migrate_sources( + repo.preload(image, [:sources]), + repo.preload(duplicate_of_image, [:sources]) + )} + end) |> Multi.run(:migrate_comments, fn _, %{} -> {:ok, Comments.migrate_comments(image, duplicate_of_image)} end) @@ -920,6 +927,17 @@ defmodule Philomena.Images do {:ok, count} end + def migrate_sources(source, target) do + sources = + (source.sources ++ target.sources) + |> Enum.uniq() + |> Enum.take(10) + + target + |> Image.sources_changeset(sources) + |> Repo.update() + end + def notify_merge(source, target) do Exq.enqueue(Exq, "notifications", NotificationWorker, ["Images", [source.id, target.id]]) end diff --git a/lib/philomena/images/image.ex b/lib/philomena/images/image.ex index 9a652f18..a9588e68 100644 --- a/lib/philomena/images/image.ex +++ b/lib/philomena/images/image.ex @@ -214,6 +214,11 @@ defmodule Philomena.Images.Image do |> SourceDiffer.diff_input(old_sources, new_sources) end + def sources_changeset(image, new_sources) do + change(image) + |> put_assoc(:sources, new_sources) + end + def tag_changeset(image, attrs, old_tags, new_tags, excluded_tags \\ []) do image |> cast(attrs, []) diff --git a/lib/philomena_web/templates/image/_source.html.slime b/lib/philomena_web/templates/image/_source.html.slime index 20c4e3fc..3264b2d4 100644 --- a/lib/philomena_web/templates/image/_source.html.slime +++ b/lib/philomena_web/templates/image/_source.html.slime @@ -38,8 +38,8 @@ p ' You can't edit the source on this image. - .flex.flex--wrap.flex--centered#image-source - p + .flex.flex--wrap.flex--column#image-source + .flex a.button.button--separate-right#edit-source data-click-focus=".js-image-source" data-click-hide="#image-source" data-click-show="#source-form" title="Edit source" accessKey="s" i.fas.fa-edit> = if !has_sources || length(@image.sources) == 1 do @@ -58,22 +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_sources + = if has_sources do + - [first_source | sources] = @image.sources .image_source__icon - i class=image_source_icon(source.source) + i class=image_source_icon(first_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 + 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/image_view.ex b/lib/philomena_web/views/image_view.ex index b3174a2d..006c7aec 100644 --- a/lib/philomena_web/views/image_view.ex +++ b/lib/philomena_web/views/image_view.ex @@ -308,18 +308,75 @@ defmodule PhilomenaWeb.ImageView do u when u in ["cdn.discordapp.com", "discordapp.com", "discord.com"] -> "fab fa-discord" + u when u in ["youtube.com", "www.youtube.com"] -> + "fab fa-youtube" + + u when u in ["pillowfort.social", "www.pillowfort.social"] -> + "fa fa-bed" + + u when u in ["vk.com", "vk.ru"] -> + "fab fa-vk" + + u when u in ["pixiv.net", "www.pixiv.net", "artfight.net", "www.artfight.net"] -> + "fa fa-paintbrush" + + u when u in ["patreon.com", "www.patreon.com"] -> + "fab fa-patreon" + + u when u in ["ych.art", "ych.commishes.com", "commishes.com"] -> + "fa fa-palette" + + u when u in ["artstation.com", "www.artstation.com"] -> + "fab fa-artstation" + + u when u in ["instagram.com", "www.instagram.com"] -> + "fab fa-instagram" + + u when u in ["reddit.com", "www.reddit.com"] -> + "fab fa-reddit" + + u when u in ["facebook.com", "www.facebook.com", "fb.me", "www.fb.me"] -> + "fab fa-facebook" + + u when u in ["tiktok.com", "www.tiktok.com"] -> + "fab fa-tiktok" + u when u in [ - "derpibooru.org", - "www.derpibooru.org", - "trixiebooru.org", - "www.trixiebooru.org", - "derpicdn.net" + "furaffinity.net", + "www.furaffinity.net", + "furbooru.org", + "inkbunny.net", + "e621.net", + "e926.net" ] -> - "fab fa-phoenix-framework" + "fa fa-paw" + + u + when u in [ + "awoo.space", + "bark.lgbt", + "equestria.social", + "foxy.social", + "mastodon.art", + "mastodon.social", + "meow.social", + "pawoo.net", + "pettingzoo.co", + "pony.social", + "vulpine.club", + "yiff.life" + ] -> + "fab fa-mastodon" link -> - if Enum.member?(site_domains, link), do: "favicon-home", else: "fa fa-link" + cond do + Enum.member?(site_domains, link) -> "favicon-home" + String.contains?(link, "tumblr") -> "fab fa-tumblr" + String.contains?(link, "deviantart") -> "fab fa-deviantart" + String.contains?(link, "sofurry") -> "fa fa-paw" + true -> "fa fa-link" + end end end end