fix source url display, provide all source urls

This commit is contained in:
Luna D 2023-05-29 13:06:41 +02:00
parent a569008267
commit e0eb226abe
No known key found for this signature in database
GPG key ID: 4B1C63448394F688
44 changed files with 90 additions and 70 deletions

View file

@ -20,12 +20,12 @@ defmodule Philomena.Polymorphic do
} }
@preloads %{ @preloads %{
"Comment" => [:user, image: [tags: :aliases]], "Comment" => [:user, image: [:sources, tags: :aliases]],
"Commission" => [:user], "Commission" => [:user],
"Conversation" => [:from, :to], "Conversation" => [:from, :to],
"DnpEntry" => [:requesting_user, :tag], "DnpEntry" => [:requesting_user, :tag],
"Gallery" => [:creator], "Gallery" => [:creator],
"Image" => [:user, tags: :aliases], "Image" => [:user, :sources, tags: :aliases],
"Post" => [:user, topic: :forum], "Post" => [:user, topic: :forum],
"Topic" => [:forum, :user], "Topic" => [:forum, :user],
"Report" => [:user] "Report" => [:user]

View file

@ -77,7 +77,7 @@ defmodule PhilomenaWeb.ActivityController do
|> filter_hidden(user, conn.params["hidden"]) |> filter_hidden(user, conn.params["hidden"])
|> order_by([i, f], desc: f.created_at) |> order_by([i, f], desc: f.created_at)
|> limit(1) |> limit(1)
|> preload(tags: :aliases) |> preload([:sources, tags: :aliases])
|> Repo.one() |> Repo.one()
streams = streams =
@ -147,9 +147,9 @@ defmodule PhilomenaWeb.ActivityController do
Elasticsearch.msearch_records( Elasticsearch.msearch_records(
[images, top_scoring, comments], [images, top_scoring, comments],
[ [
preload(Image, tags: :aliases), preload(Image, [:sources, tags: :aliases]),
preload(Image, tags: :aliases), preload(Image, [:sources, tags: :aliases]),
preload(Comment, [:user, image: [tags: :aliases]]) preload(Comment, [:user, image: [:sources, tags: :aliases]])
] ]
) )
@ -160,10 +160,10 @@ defmodule PhilomenaWeb.ActivityController do
Elasticsearch.msearch_records( Elasticsearch.msearch_records(
[images, top_scoring, comments, watched], [images, top_scoring, comments, watched],
[ [
preload(Image, tags: :aliases), preload(Image, [:sources, tags: :aliases]),
preload(Image, tags: :aliases), preload(Image, [:sources, tags: :aliases]),
preload(Comment, [:user, image: [tags: :aliases]]), preload(Comment, [:user, image: [:sources, tags: :aliases]]),
preload(Image, tags: :aliases) preload(Image, [:sources, tags: :aliases])
] ]
) )
end end

View file

@ -16,7 +16,7 @@ defmodule PhilomenaWeb.Api.Json.Image.FeaturedController do
|> where([i], i.hidden_from_users == false) |> where([i], i.hidden_from_users == false)
|> order_by([_i, f], desc: f.created_at) |> order_by([_i, f], desc: f.created_at)
|> limit(1) |> limit(1)
|> preload([:user, :intensity, tags: :aliases]) |> preload([:user, :intensity, :sources, tags: :aliases])
|> Repo.one() |> Repo.one()
case featured_image do case featured_image do

View file

@ -20,7 +20,7 @@ defmodule PhilomenaWeb.Api.Json.ImageController do
image = image =
Image Image
|> where(id: ^id) |> where(id: ^id)
|> preload([:user, :intensity, tags: :aliases]) |> preload([:user, :intensity, :sources, tags: :aliases])
|> Repo.one() |> Repo.one()
case image do case image do

View file

@ -37,7 +37,7 @@ defmodule PhilomenaWeb.Api.Json.OembedController do
defp load_image(id) do defp load_image(id) do
Image Image
|> where(id: ^id, hidden_from_users: false) |> where(id: ^id, hidden_from_users: false)
|> preload([:user, tags: :aliases]) |> preload([:user, :sources, tags: :aliases])
|> Repo.one() |> Repo.one()
end end

View file

@ -8,7 +8,7 @@ defmodule PhilomenaWeb.Api.Json.Search.ImageController do
import Ecto.Query import Ecto.Query
def index(conn, params) do 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 user = conn.assigns.current_user
case ImageLoader.search_string(conn, params["q"]) do case ImageLoader.search_string(conn, params["q"]) do

View file

@ -9,7 +9,7 @@ defmodule PhilomenaWeb.Api.Rss.WatchedController do
def index(conn, _params) do def index(conn, _params) do
{:ok, {images, _tags}} = ImageLoader.search_string(conn, "my:watched") {: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 # NB: this is RSS, but using the RSS format causes Phoenix not to
# escape HTML # escape HTML

View file

@ -36,7 +36,7 @@ defmodule PhilomenaWeb.CommentController do
conn.assigns.pagination conn.assigns.pagination
) )
|> Elasticsearch.search_records( |> 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) rendered = MarkdownRenderer.render_collection(comments.entries, conn)

View file

@ -74,7 +74,7 @@ defmodule PhilomenaWeb.CommissionController do
where: ui.updated_at >= ago(2, "week"), where: ui.updated_at >= ago(2, "week"),
group_by: c.id, group_by: c.id,
order_by: [asc: fragment("random()")], 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 end
defp presence(nil), defp presence(nil),

View file

@ -12,7 +12,7 @@ defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do
SourceChange SourceChange
|> where(fingerprint: ^fingerprint) |> where(fingerprint: ^fingerprint)
|> order_by(desc: :id) |> order_by(desc: :id)
|> preload([:user, image: [:user, tags: :aliases]]) |> preload([:user, image: [:user, :sources, tags: :aliases]])
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)
render(conn, "index.html", render(conn, "index.html",

View file

@ -12,7 +12,7 @@ defmodule PhilomenaWeb.FingerprintProfile.TagChangeController do
TagChange TagChange
|> where(fingerprint: ^fingerprint) |> where(fingerprint: ^fingerprint)
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, tags: :aliases]]) |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -16,7 +16,7 @@ defmodule PhilomenaWeb.GalleryController do
plug :load_and_authorize_resource, plug :load_and_authorize_resource,
model: Gallery, model: Gallery,
except: [:index], except: [:index],
preload: [:creator, thumbnail: [tags: :aliases]] preload: [:creator, thumbnail: [:sources, tags: :aliases]]
def index(conn, params) do def index(conn, params) do
galleries = galleries =
@ -32,7 +32,9 @@ defmodule PhilomenaWeb.GalleryController do
}, },
conn.assigns.pagination 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", render(conn, "index.html",
title: "Galleries", title: "Galleries",
@ -63,9 +65,9 @@ defmodule PhilomenaWeb.GalleryController do
Elasticsearch.msearch_records_with_hits( Elasticsearch.msearch_records_with_hits(
[images, gallery_prev, gallery_next], [images, gallery_prev, gallery_next],
[ [
preload(Image, tags: :aliases), preload(Image, [:sources, tags: :aliases]),
preload(Image, tags: :aliases), preload(Image, [:sources, tags: :aliases]),
preload(Image, tags: :aliases) preload(Image, [:sources, tags: :aliases])
] ]
) )

View file

@ -18,7 +18,7 @@ defmodule PhilomenaWeb.Image.Comment.ReportController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [tags: :aliases] preload: [:sources, tags: :aliases]
plug PhilomenaWeb.LoadCommentPlug plug PhilomenaWeb.LoadCommentPlug

View file

@ -24,7 +24,7 @@ defmodule PhilomenaWeb.Image.CommentController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [tags: :aliases] preload: [:sources, tags: :aliases]
plug :verify_authorized when action in [:show] plug :verify_authorized when action in [:show]
plug PhilomenaWeb.FilterForcedUsersPlug when action in [:create, :edit, :update] plug PhilomenaWeb.FilterForcedUsersPlug when action in [:create, :edit, :update]

View file

@ -12,7 +12,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:user, tags: :aliases] preload: [:user, :sources, tags: :aliases]
def update(conn, %{"image" => image_params}) do def update(conn, %{"image" => image_params}) do
image = conn.assigns.image image = conn.assigns.image

View file

@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.FaveController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [tags: :aliases] preload: [:sources, tags: :aliases]
plug PhilomenaWeb.FilterForcedUsersPlug plug PhilomenaWeb.FilterForcedUsersPlug

View file

@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.RelatedController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:faves, tags: :aliases] preload: [:faves, :sources, tags: :aliases]
def index(conn, _params) do def index(conn, _params) do
image = conn.assigns.image image = conn.assigns.image
@ -60,7 +60,7 @@ defmodule PhilomenaWeb.Image.RelatedController do
pagination: %{conn.assigns.image_pagination | page_number: 1} 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) interactions = Interactions.user_interactions(images, user)

View file

@ -17,7 +17,7 @@ defmodule PhilomenaWeb.Image.ReportController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [tags: :aliases] preload: [:sources, tags: :aliases]
def new(conn, _params) do def new(conn, _params) do
image = conn.assigns.image image = conn.assigns.image

View file

@ -11,7 +11,7 @@ defmodule PhilomenaWeb.Image.ReportingController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [tags: :aliases] preload: [:sources, tags: :aliases]
def show(conn, _params) do def show(conn, _params) do
image = conn.assigns.image image = conn.assigns.image
@ -21,8 +21,8 @@ defmodule PhilomenaWeb.Image.ReportingController do
|> preload([ |> preload([
:user, :user,
:modifier, :modifier,
image: [:user, tags: :aliases], image: [:user, :sources, tags: :aliases],
duplicate_of_image: [:user, tags: :aliases] duplicate_of_image: [:user, :sources, tags: :aliases]
]) ])
|> where([d], d.image_id == ^image.id or d.duplicate_of_image_id == ^image.id) |> where([d], d.image_id == ^image.id or d.duplicate_of_image_id == ^image.id)
|> Repo.all() |> Repo.all()

View file

@ -15,7 +15,7 @@ defmodule PhilomenaWeb.Image.SourceChangeController do
source_changes = source_changes =
SourceChange SourceChange
|> where(image_id: ^image.id) |> where(image_id: ^image.id)
|> preload([:user, image: [:user, tags: :aliases]]) |> preload([:user, image: [:user, :sources, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -23,7 +23,7 @@ defmodule PhilomenaWeb.Image.TagChangeController do
TagChange TagChange
|> where(image_id: ^image.id) |> where(image_id: ^image.id)
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, tags: :aliases]]) |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -23,7 +23,7 @@ defmodule PhilomenaWeb.Image.TagController do
plug :load_and_authorize_resource, plug :load_and_authorize_resource,
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
preload: [:user, :locked_tags, tags: :aliases] preload: [:user, :locked_tags, :sources, tags: :aliases]
def update(conn, %{"image" => image_params}) do def update(conn, %{"image" => image_params}) do
attributes = conn.assigns.attributes attributes = conn.assigns.attributes
@ -62,7 +62,7 @@ defmodule PhilomenaWeb.Image.TagController do
image = image =
image image
|> Repo.preload([tags: :aliases], force: true) |> Repo.preload([:sources, tags: :aliases], force: true)
changeset = Images.change_image(image) changeset = Images.change_image(image)
@ -78,7 +78,7 @@ defmodule PhilomenaWeb.Image.TagController do
{:error, :image, changeset, _} -> {:error, :image, changeset, _} ->
image = image =
image image
|> Repo.preload([tags: :aliases], force: true) |> Repo.preload([:sources, tags: :aliases], force: true)
conn conn
|> put_view(PhilomenaWeb.ImageView) |> put_view(PhilomenaWeb.ImageView)

View file

@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.VoteController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [tags: :aliases] preload: [:sources, tags: :aliases]
plug PhilomenaWeb.FilterForcedUsersPlug plug PhilomenaWeb.FilterForcedUsersPlug

View file

@ -40,7 +40,7 @@ defmodule PhilomenaWeb.ImageController do
{:ok, {images, _tags}} = {:ok, {images, _tags}} =
ImageLoader.search_string(conn, "created_at.lte:3 minutes ago, -thumbnails_generated:false") 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) interactions = Interactions.user_interactions(images, conn.assigns.current_user)

View file

@ -14,7 +14,7 @@ defmodule PhilomenaWeb.IpProfile.SourceChangeController do
SourceChange SourceChange
|> where(ip: ^ip) |> where(ip: ^ip)
|> order_by(desc: :id) |> order_by(desc: :id)
|> preload([:user, image: [:user, tags: :aliases]]) |> preload([:user, image: [:user, :sources, tags: :aliases]])
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)
render(conn, "index.html", render(conn, "index.html",

View file

@ -14,7 +14,7 @@ defmodule PhilomenaWeb.IpProfile.TagChangeController do
TagChange TagChange
|> where(ip: ^ip) |> where(ip: ^ip)
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, tags: :aliases]]) |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -15,9 +15,9 @@ defmodule PhilomenaWeb.Profile.Commission.ItemController do
preload: [ preload: [
:verified_links, :verified_links,
commission: [ commission: [
sheet_image: [tags: :aliases], sheet_image: [:sources, tags: :aliases],
user: [awards: :badge], user: [awards: :badge],
items: [example_image: [tags: :aliases]] items: [example_image: [:sources, tags: :aliases]]
] ]
], ],
persisted: true persisted: true

View file

@ -20,9 +20,9 @@ defmodule PhilomenaWeb.Profile.Commission.ReportController do
preload: [ preload: [
:verified_links, :verified_links,
commission: [ commission: [
sheet_image: [tags: :aliases], sheet_image: [:sources, tags: :aliases],
user: [awards: :badge], user: [awards: :badge],
items: [example_image: [tags: :aliases]] items: [example_image: [:sources, tags: :aliases]]
] ]
], ],
persisted: true persisted: true

View file

@ -15,9 +15,9 @@ defmodule PhilomenaWeb.Profile.CommissionController do
preload: [ preload: [
:verified_links, :verified_links,
commission: [ commission: [
sheet_image: [tags: :aliases], sheet_image: [:sources, tags: :aliases],
user: [awards: :badge], user: [awards: :badge],
items: [example_image: [tags: :aliases]] items: [example_image: [:sources, tags: :aliases]]
] ]
], ],
persisted: true persisted: true

View file

@ -25,7 +25,7 @@ defmodule PhilomenaWeb.Profile.SourceChangeController do
[sc, i], [sc, i],
sc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true) 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) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -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) tc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true)
) )
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, tags: :aliases]]) |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -28,7 +28,10 @@ defmodule PhilomenaWeb.ProfileController do
awards: [:badge, :awarded_by], awards: [:badge, :awarded_by],
public_links: :tag, public_links: :tag,
verified_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 plug :set_admin_metadata
@ -119,10 +122,10 @@ defmodule PhilomenaWeb.ProfileController do
Elasticsearch.msearch_records( Elasticsearch.msearch_records(
[recent_uploads, recent_faves, recent_artwork, recent_comments, recent_posts], [recent_uploads, recent_faves, recent_artwork, recent_comments, recent_posts],
[ [
preload(Image, tags: :aliases), preload(Image, [:sources, tags: :aliases]),
preload(Image, tags: :aliases), preload(Image, [:sources, tags: :aliases]),
preload(Image, tags: :aliases), preload(Image, [:sources, tags: :aliases]),
preload(Comment, user: [awards: :badge], image: [tags: :aliases]), preload(Comment, user: [awards: :badge], image: [:sources, tags: :aliases]),
preload(Post, user: [awards: :badge], topic: :forum) preload(Post, user: [awards: :badge], topic: :forum)
] ]
) )
@ -144,7 +147,7 @@ defmodule PhilomenaWeb.ProfileController do
recent_galleries = recent_galleries =
Gallery Gallery
|> where(creator_id: ^user.id) |> where(creator_id: ^user.id)
|> preload([:creator, thumbnail: [tags: :aliases]]) |> preload([:creator, thumbnail: [:sources, tags: :aliases]])
|> limit(4) |> limit(4)
|> Repo.all() |> Repo.all()

View file

@ -12,7 +12,12 @@ defmodule PhilomenaWeb.SearchController do
case ImageLoader.search_string(conn, params["q"]) do case ImageLoader.search_string(conn, params["q"]) do
{:ok, {images, tags}} -> {: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) interactions = Interactions.user_interactions(images, user)
conn conn

View file

@ -16,7 +16,7 @@ defmodule PhilomenaWeb.Tag.TagChangeController do
TagChange TagChange
|> where(tag_id: ^tag.id) |> where(tag_id: ^tag.id)
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, tags: :aliases]]) |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -57,7 +57,7 @@ defmodule PhilomenaWeb.TagController do
{images, _tags} = ImageLoader.query(conn, %{term: %{"namespaced_tags.name" => tag.name}}) {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) interactions = Interactions.user_interactions(images, user)

View file

@ -20,7 +20,7 @@ defmodule PhilomenaWeb.ImageReverse do
dist = normalize_dist(image_params) dist = normalize_dist(image_params)
DuplicateReports.duplicates_of(intensities, aspect, dist, dist) DuplicateReports.duplicates_of(intensities, aspect, dist, dist)
|> preload([:user, :intensity, [tags: :aliases]]) |> preload([:user, :intensity, [:sources, tags: :aliases]])
|> Repo.all() |> Repo.all()
end end
end end

View file

@ -45,7 +45,7 @@ defmodule PhilomenaWeb.MarkdownRenderer do
Image Image
|> where([i], i.id in ^ids) |> where([i], i.id in ^ids)
|> preload(tags: :aliases) |> preload([:sources, tags: :aliases])
|> Repo.all() |> Repo.all()
|> Map.new(&{&1.id, &1}) |> Map.new(&{&1.id, &1})
end end

View file

@ -28,7 +28,7 @@
p Loading... p Loading...
.block__tab.hidden data-tab="sharing" .block__tab.hidden data-tab="sharing"
#embed_options #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 h5 Derpibooru
p p
strong> Small thumbnail strong> Small thumbnail

View file

@ -17,8 +17,8 @@ meta name="format-detection" content="telephone=no"
= for tag <- artist_tags(image.tags) do = for tag <- artist_tags(image.tags) do
meta property="dc:creator" content=tag.name_in_namespace meta property="dc:creator" content=tag.name_in_namespace
= if image.source_url not in [nil, ""] do = if image_has_sources(image) do
meta property="foaf:primaryTopic" content=image.source_url 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" 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"

View file

@ -48,9 +48,9 @@ h1 Reverse Search
th th
h3 = link "##{match.id}", to: Routes.image_path(@conn, :show, match) h3 = link "##{match.id}", to: Routes.image_path(@conn, :show, match)
p p
= if match.source_url not in [nil, ""] do = if image_has_sources(match) do
span.source_url span.source_url
= link "Source", to: match.source_url = link "Source", to: image_first_source(match)
- else - else
' Unknown source ' Unknown source

View file

@ -80,7 +80,9 @@ defmodule PhilomenaWeb.Api.Json.ImageView do
comment_count: image.comments_count, comment_count: image.comments_count,
tag_count: length(image.tags), tag_count: length(image.tags),
description: image.description, 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), view_url: ImageView.pretty_url(image, false, false),
representations: ImageView.thumb_urls(image, false), representations: ImageView.thumb_urls(image, false),
thumbnails_generated: image.thumbnails_generated, thumbnails_generated: image.thumbnails_generated,

View file

@ -12,7 +12,7 @@ defmodule PhilomenaWeb.Api.Json.OembedView do
version: "1.0", version: "1.0",
type: "photo", type: "photo",
title: "##{image.id} - #{tag_list(image)} - Derpibooru", title: "##{image.id} - #{tag_list(image)} - Derpibooru",
author_url: image.source_url || "", author_url: image_first_source(image),
author_name: artist_tags(image.tags), author_name: artist_tags(image.tags),
provider_name: "Derpibooru", provider_name: "Derpibooru",
provider_url: PhilomenaWeb.Endpoint.url(), provider_url: PhilomenaWeb.Endpoint.url(),

View file

@ -241,6 +241,12 @@ defmodule PhilomenaWeb.AppView do
] ]
end 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: nil}}), do: %{}
def get_flash(%{assigns: %{flash: flash}}), do: flash def get_flash(%{assigns: %{flash: flash}}), do: flash
def get_flash(_), do: %{} def get_flash(_), do: %{}

View file

@ -162,7 +162,9 @@ defmodule PhilomenaWeb.ImageView do
downvotes: image.downvotes_count, downvotes: image.downvotes_count,
comment_count: image.comments_count, comment_count: image.comments_count,
created_at: DateTime.to_iso8601(image.created_at), 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))), uris: Jason.encode!(thumb_urls(image, can?(conn, :show, image))),
width: image.image_width, width: image.image_width,
height: image.image_height, height: image.image_height,