mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-25 15:39:19 +00:00
Merge pull request 'Pass remote follow avatar into media proxy' (#64) from norm/akkoma:remote-avatar-media-proxy into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/64
This commit is contained in:
commit
d8c2b221a3
|
@ -7,5 +7,9 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowView do
|
|||
import Phoenix.HTML.Form
|
||||
alias Pleroma.Web.Gettext
|
||||
|
||||
defdelegate avatar_url(user), to: Pleroma.User
|
||||
def avatar_url(user) do
|
||||
user
|
||||
|> Pleroma.User.avatar_url()
|
||||
|> Pleroma.Web.MediaProxy.url()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -410,4 +410,49 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
|||
assert response =~ "Error following account"
|
||||
end
|
||||
end
|
||||
|
||||
describe "avatar url" do
|
||||
test "without media proxy" do
|
||||
clear_config([:media_proxy, :enabled], false)
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
avatar: %{"url" => [%{"href" => "https://remote.org/avatar.png"}]}
|
||||
})
|
||||
|
||||
avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
|
||||
|
||||
assert avatar_url == "https://remote.org/avatar.png"
|
||||
end
|
||||
|
||||
test "with media proxy" do
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
avatar: %{"url" => [%{"href" => "https://remote.org/avatar.png"}]}
|
||||
})
|
||||
|
||||
avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
|
||||
url = Pleroma.Web.Endpoint.url()
|
||||
|
||||
assert String.starts_with?(avatar_url, url)
|
||||
end
|
||||
|
||||
test "local avatar is not proxied" do
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
local: true,
|
||||
avatar: %{"url" => [%{"href" => "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"}]}
|
||||
})
|
||||
|
||||
avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
|
||||
|
||||
assert avatar_url == "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue