Merge branch 'use-reverse-proxy-for-remote-images' into 'master'
Add proxy route and proxify pics everywhere See merge request framasoft/mobilizon!142
This commit is contained in:
commit
2b8d4c85c2
@ -8,6 +8,7 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
alias Mobilizon.Media.Picture
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Users.User
|
||||
alias MobilizonWeb.Resolvers.Person
|
||||
|
||||
# We limit the max number of events that can be retrieved
|
||||
@event_max_limit 100
|
||||
@ -28,7 +29,7 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
{:error, "Event with UUID #{uuid} not found"}
|
||||
|
||||
event ->
|
||||
{:ok, event}
|
||||
{:ok, Map.put(event, :organizer_actor, Person.proxify_pictures(event.organizer_actor))}
|
||||
end
|
||||
end
|
||||
|
||||
@ -116,7 +117,7 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
}),
|
||||
participant <-
|
||||
Map.put(participant, :event, event)
|
||||
|> Map.put(:actor, actor) do
|
||||
|> Map.put(:actor, Person.proxify_pictures(actor)) do
|
||||
{:ok, participant}
|
||||
else
|
||||
{:is_owned, false} ->
|
||||
|
@ -7,16 +7,17 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Activity
|
||||
alias MobilizonWeb.Resolvers.Person
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
Find a group
|
||||
"""
|
||||
def find_group(_parent, %{preferred_username: name}, _resolution) do
|
||||
case ActivityPub.find_or_make_group_from_nickname(name) do
|
||||
{:ok, actor} ->
|
||||
{:ok, actor}
|
||||
|
||||
with {:ok, actor} <- ActivityPub.find_or_make_group_from_nickname(name),
|
||||
actor <- Person.proxify_pictures(actor) do
|
||||
{:ok, actor}
|
||||
else
|
||||
_ ->
|
||||
{:error, "Group with name #{name} not found"}
|
||||
end
|
||||
@ -26,7 +27,8 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||
Lists all groups
|
||||
"""
|
||||
def list_groups(_parent, %{page: page, limit: limit}, _resolution) do
|
||||
{:ok, Actors.list_groups(page, limit)}
|
||||
{:ok,
|
||||
Actors.list_groups(page, limit) |> Enum.map(fn actor -> Person.proxify_pictures(actor) end)}
|
||||
end
|
||||
|
||||
@doc """
|
||||
@ -141,7 +143,12 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||
actor_id: actor.id,
|
||||
role: role
|
||||
}) do
|
||||
{:ok, %{parent: group, actor: actor, role: role}}
|
||||
{:ok,
|
||||
%{
|
||||
parent: group |> Person.proxify_pictures(),
|
||||
actor: actor |> Person.proxify_pictures(),
|
||||
role: role
|
||||
}}
|
||||
else
|
||||
{:is_owned, false} ->
|
||||
{:error, "Actor id is not owned by authenticated user"}
|
||||
|
@ -13,10 +13,10 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||
Find a person
|
||||
"""
|
||||
def find_person(_parent, %{preferred_username: name}, _resolution) do
|
||||
case ActivityPub.find_or_make_person_from_nickname(name) do
|
||||
{:ok, actor} ->
|
||||
{:ok, actor}
|
||||
|
||||
with {:ok, actor} <- ActivityPub.find_or_make_person_from_nickname(name),
|
||||
actor <- proxify_pictures(actor) do
|
||||
{:ok, actor}
|
||||
else
|
||||
_ ->
|
||||
{:error, "Person with name #{name} not found"}
|
||||
end
|
||||
@ -135,4 +135,26 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||
{:error, "Actor id is not owned by authenticated user"}
|
||||
end
|
||||
end
|
||||
|
||||
def proxify_pictures(%Actor{} = actor) do
|
||||
actor
|
||||
|> proxify_avatar
|
||||
|> proxify_banner
|
||||
end
|
||||
|
||||
@spec proxify_avatar(Actor.t()) :: Actor.t()
|
||||
defp proxify_avatar(%Actor{avatar: %{url: avatar_url} = avatar} = actor) do
|
||||
actor |> Map.put(:avatar, avatar |> Map.put(:url, MobilizonWeb.MediaProxy.url(avatar_url)))
|
||||
end
|
||||
|
||||
@spec proxify_avatar(Actor.t()) :: Actor.t()
|
||||
defp proxify_avatar(%Actor{} = actor), do: actor
|
||||
|
||||
@spec proxify_banner(Actor.t()) :: Actor.t()
|
||||
defp proxify_banner(%Actor{banner: %{url: banner_url} = banner} = actor) do
|
||||
actor |> Map.put(:banner, banner |> Map.put(:url, MobilizonWeb.MediaProxy.url(banner_url)))
|
||||
end
|
||||
|
||||
@spec proxify_banner(Actor.t()) :: Actor.t()
|
||||
defp proxify_banner(%Actor{} = actor), do: actor
|
||||
end
|
||||
|
@ -39,6 +39,9 @@ defmodule MobilizonWeb.Router do
|
||||
plug(:put_secure_browser_headers)
|
||||
end
|
||||
|
||||
pipeline :remote_media do
|
||||
end
|
||||
|
||||
scope "/api" do
|
||||
pipe_through(:graphql)
|
||||
|
||||
@ -94,6 +97,13 @@ defmodule MobilizonWeb.Router do
|
||||
post("/inbox", ActivityPubController, :inbox)
|
||||
end
|
||||
|
||||
scope "/proxy/", MobilizonWeb do
|
||||
pipe_through(:remote_media)
|
||||
|
||||
get("/:sig/:url", MediaProxyController, :remote)
|
||||
get("/:sig/:url/:filename", MediaProxyController, :remote)
|
||||
end
|
||||
|
||||
if Mix.env() == :dev do
|
||||
# If using Phoenix
|
||||
forward("/sent_emails", Bamboo.SentEmailViewerPlug)
|
||||
|
@ -5,6 +5,7 @@ defmodule MobilizonWeb.JsonLD.ObjectView do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias MobilizonWeb.JsonLD.ObjectView
|
||||
alias MobilizonWeb.MediaProxy
|
||||
|
||||
def render("event.json", %{event: %Event{} = event}) do
|
||||
# TODO: event.description is actually markdown!
|
||||
@ -25,7 +26,7 @@ defmodule MobilizonWeb.JsonLD.ObjectView do
|
||||
json_ld =
|
||||
if event.picture do
|
||||
Map.put(json_ld, "image", [
|
||||
event.picture.file.url
|
||||
event.picture.file.url |> MediaProxy.url()
|
||||
])
|
||||
else
|
||||
json_ld
|
||||
|
@ -13,6 +13,7 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
import MobilizonWeb.Gettext
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.MediaProxy
|
||||
require Logger
|
||||
|
||||
@version Mix.Project.config()[:version]
|
||||
@ -76,14 +77,14 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
|
||||
feed =
|
||||
if actor.avatar do
|
||||
Feed.icon(feed, actor.avatar.url)
|
||||
feed |> Feed.icon(actor.avatar.url |> MediaProxy.url())
|
||||
else
|
||||
feed
|
||||
end
|
||||
|
||||
feed =
|
||||
if actor.banner do
|
||||
Feed.logo(feed, actor.banner.url)
|
||||
feed |> Feed.logo(actor.banner.url |> MediaProxy.url())
|
||||
else
|
||||
feed
|
||||
end
|
||||
|
@ -1,6 +1,7 @@
|
||||
defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
|
||||
alias Phoenix.HTML.Tag
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias MobilizonWeb.MediaProxy
|
||||
|
||||
def build_tags(%Actor{} = actor) do
|
||||
tags = [
|
||||
@ -15,7 +16,8 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
|
||||
if is_nil(actor.avatar) do
|
||||
tags
|
||||
else
|
||||
tags ++ [Tag.tag(:meta, property: "og:image", content: actor.avatar.url)]
|
||||
tags ++
|
||||
[Tag.tag(:meta, property: "og:image", content: actor.avatar.url |> MediaProxy.url())]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,6 +3,7 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
alias Phoenix.HTML.Tag
|
||||
alias Mobilizon.Events.Event
|
||||
alias MobilizonWeb.JsonLD.ObjectView
|
||||
alias MobilizonWeb.MediaProxy
|
||||
|
||||
def build_tags(%Event{} = event) do
|
||||
tags = [
|
||||
@ -18,7 +19,10 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
else
|
||||
tags ++
|
||||
[
|
||||
Tag.tag(:meta, property: "og:image", content: event.picture.file.url)
|
||||
Tag.tag(:meta,
|
||||
property: "og:image",
|
||||
content: event.picture.file.url |> MediaProxy.url()
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user