forked from AkkomaGang/akkoma
AccountView: Use mediaproxy URLs for emojis
Also use atom keys in emoji maps instead of binaries Closes #1810
This commit is contained in:
parent
78c46fb7ba
commit
8f6d428880
2 changed files with 38 additions and 9 deletions
|
@ -182,12 +182,14 @@ defp do_render("show.json", %{user: user} = opts) do
|
||||||
bot = user.actor_type in ["Application", "Service"]
|
bot = user.actor_type in ["Application", "Service"]
|
||||||
|
|
||||||
emojis =
|
emojis =
|
||||||
Enum.map(user.emoji, fn {shortcode, url} ->
|
Enum.map(user.emoji, fn {shortcode, raw_url} ->
|
||||||
|
url = MediaProxy.url(raw_url)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
"shortcode" => shortcode,
|
shortcode: shortcode,
|
||||||
"url" => url,
|
url: url,
|
||||||
"static_url" => url,
|
static_url: url,
|
||||||
"visible_in_picker" => false
|
visible_in_picker: false
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,10 @@ test "Represent a user account" do
|
||||||
header_static: "http://localhost:4001/images/banner.png",
|
header_static: "http://localhost:4001/images/banner.png",
|
||||||
emojis: [
|
emojis: [
|
||||||
%{
|
%{
|
||||||
"static_url" => "/file.png",
|
static_url: "/file.png",
|
||||||
"url" => "/file.png",
|
url: "/file.png",
|
||||||
"shortcode" => "karjalanpiirakka",
|
shortcode: "karjalanpiirakka",
|
||||||
"visible_in_picker" => false
|
visible_in_picker: false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
fields: [],
|
fields: [],
|
||||||
|
@ -491,4 +491,31 @@ test "shows non-zero when historical unapproved requests are present" do
|
||||||
AccountView.render("show.json", %{user: user, for: user})
|
AccountView.render("show.json", %{user: user, for: user})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "uses mediaproxy urls when it's enabled" do
|
||||||
|
clear_config([:media_proxy, :enabled], true)
|
||||||
|
|
||||||
|
user =
|
||||||
|
insert(:user,
|
||||||
|
avatar: %{"url" => [%{"href" => "https://evil.website/avatar.png"}]},
|
||||||
|
banner: %{"url" => [%{"href" => "https://evil.website/banner.png"}]},
|
||||||
|
emoji: %{"joker_smile" => "https://evil.website/society.png"}
|
||||||
|
)
|
||||||
|
|
||||||
|
AccountView.render("show.json", %{user: user})
|
||||||
|
|> Enum.all?(fn
|
||||||
|
{key, url} when key in [:avatar, :avatar_static, :header, :header_static] ->
|
||||||
|
String.starts_with?(url, Pleroma.Web.base_url())
|
||||||
|
|
||||||
|
{:emojis, emojis} ->
|
||||||
|
Enum.all?(emojis, fn %{url: url, static_url: static_url} ->
|
||||||
|
String.starts_with?(url, Pleroma.Web.base_url()) &&
|
||||||
|
String.starts_with?(static_url, Pleroma.Web.base_url())
|
||||||
|
end)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
true
|
||||||
|
end)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue