Add header image to masto api.

This commit is contained in:
Roger Braun 2017-09-10 10:37:34 +02:00
parent d66d69c3b4
commit e8975d06be
2 changed files with 9 additions and 4 deletions

View File

@ -2,10 +2,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
use Pleroma.Web, :view use Pleroma.Web, :view
alias Pleroma.User alias Pleroma.User
defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href
defp image_url(_), do: nil
def render("account.json", %{user: user}) do def render("account.json", %{user: user}) do
image = User.avatar_url(user) image = User.avatar_url(user)
user_info = User.user_info(user) user_info = User.user_info(user)
header = image_url(user.info["banner"]) || "https://placehold.it/700x335"
%{ %{
id: user.id, id: user.id,
username: user.nickname, username: user.nickname,
@ -20,8 +25,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
url: user.ap_id, url: user.ap_id,
avatar: image, avatar: image,
avatar_static: image, avatar_static: image,
header: "", header: header,
header_static: "" header_static: header
} }
end end

View File

@ -20,8 +20,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
url: user.ap_id, url: user.ap_id,
avatar: "https://placehold.it/48x48", avatar: "https://placehold.it/48x48",
avatar_static: "https://placehold.it/48x48", avatar_static: "https://placehold.it/48x48",
header: "", header: "https://placehold.it/700x335",
header_static: "" header_static: "https://placehold.it/700x335"
} }
assert expected == AccountView.render("account.json", %{user: user}) assert expected == AccountView.render("account.json", %{user: user})