philomena/lib/philomena_web/views/api/json/oembed_view.ex

33 lines
884 B
Elixir
Raw Normal View History

2021-02-11 02:01:05 +01:00
defmodule PhilomenaWeb.Api.Json.OembedView do
use PhilomenaWeb, :view
def render("error.json", _assigns) do
%{
error: "Couldn't find an image"
}
end
def render("show.json", %{image: image}) do
%{
version: "1.0",
type: "photo",
2024-05-20 19:04:12 +02:00
title: "##{image.id} - #{tag_list(image)} - #{gettext("Philomena Site")}",
author_url: image_first_source(image),
2021-02-11 02:01:05 +01:00
author_name: artist_tags(image.tags),
2024-05-20 19:04:12 +02:00
provider_name: gettext("Philomena Site"),
2021-02-11 02:01:05 +01:00
provider_url: PhilomenaWeb.Endpoint.url(),
cache_age: 7200,
2024-05-20 19:04:12 +02:00
philomena_id: image.id,
philomena_score: image.score,
philomena_comments: image.comments_count,
philomena_tags: Enum.map(image.tags, & &1.name)
2021-02-11 02:01:05 +01:00
}
end
defp artist_tags(tags) do
tags
2021-02-25 20:57:31 +01:00
|> Enum.filter(&(&1.namespace == "artist"))
2021-02-11 02:01:05 +01:00
|> Enum.map_join(", ", & &1.name_in_namespace)
end
end