Save remote profiles avatars & banners locally
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -13,7 +13,7 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
alias Mobilizon.Storage.Page
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias Mobilizon.Web.{Endpoint, MediaProxy}
|
||||
alias Mobilizon.Web.Endpoint
|
||||
alias Mobilizon.Web.Router.Helpers, as: Routes
|
||||
|
||||
require Logger
|
||||
@@ -85,14 +85,14 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
|
||||
feed =
|
||||
if actor.avatar do
|
||||
feed |> Feed.icon(actor.avatar.url |> MediaProxy.url())
|
||||
feed |> Feed.icon(actor.avatar.url)
|
||||
else
|
||||
feed
|
||||
end
|
||||
|
||||
feed =
|
||||
if actor.banner do
|
||||
feed |> Feed.logo(actor.banner.url |> MediaProxy.url())
|
||||
feed |> Feed.logo(actor.banner.url)
|
||||
else
|
||||
feed
|
||||
end
|
||||
|
||||
22
lib/service/http/remote_media_downloader_client.ex
Normal file
22
lib/service/http/remote_media_downloader_client.ex
Normal file
@@ -0,0 +1,22 @@
|
||||
defmodule Mobilizon.Service.HTTP.RemoteMediaDownloaderClient do
|
||||
@moduledoc """
|
||||
Tesla HTTP Basic Client that fetches HTML to extract metadata preview
|
||||
"""
|
||||
|
||||
use Tesla
|
||||
alias Mobilizon.Config
|
||||
|
||||
@default_opts [
|
||||
recv_timeout: 20_000
|
||||
]
|
||||
|
||||
adapter(Tesla.Adapter.Hackney, @default_opts)
|
||||
|
||||
@user_agent Config.instance_user_agent()
|
||||
|
||||
plug(Tesla.Middleware.FollowRedirects)
|
||||
|
||||
plug(Tesla.Middleware.Timeout, timeout: 10_000)
|
||||
|
||||
plug(Tesla.Middleware.Headers, [{"User-Agent", @user_agent}])
|
||||
end
|
||||
@@ -3,7 +3,6 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
|
||||
alias Phoenix.HTML.Tag
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Web.JsonLD.ObjectView
|
||||
alias Mobilizon.Web.MediaProxy
|
||||
import Mobilizon.Service.Metadata.Utils, only: [process_description: 2, default_description: 1]
|
||||
|
||||
def build_tags(_actor, _locale \\ "en")
|
||||
@@ -36,7 +35,7 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do
|
||||
tags
|
||||
else
|
||||
tags ++
|
||||
[Tag.tag(:meta, property: "og:image", content: actor.avatar.url |> MediaProxy.url())]
|
||||
[Tag.tag(:meta, property: "og:image", content: actor.avatar.url)]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
alias Phoenix.HTML.Tag
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Web.JsonLD.ObjectView
|
||||
alias Mobilizon.Web.MediaProxy
|
||||
import Mobilizon.Service.Metadata.Utils, only: [process_description: 2, strip_tags: 1]
|
||||
|
||||
def build_tags(%Event{} = event, locale \\ "en") do
|
||||
@@ -28,7 +27,7 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
[
|
||||
Tag.tag(:meta,
|
||||
property: "og:image",
|
||||
content: event.picture.file.url |> MediaProxy.url()
|
||||
content: event.picture.file.url
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
@@ -47,6 +47,14 @@ defmodule Mobilizon.Service.RichMedia.Parser do
|
||||
{:error, "Cachex error: #{inspect(e)}"}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get a filename for the fetched data, using the response header or the last part of the URL
|
||||
"""
|
||||
@spec get_filename_from_response(Enum.t(), String.t()) :: String.t() | nil
|
||||
def get_filename_from_response(response_headers, url) do
|
||||
get_filename_from_headers(response_headers) || get_filename_from_url(url)
|
||||
end
|
||||
|
||||
@spec parse_url(String.t(), Enum.t()) :: {:ok, map()} | {:error, any()}
|
||||
defp parse_url(url, options \\ []) do
|
||||
user_agent = Keyword.get(options, :user_agent, Config.instance_user_agent())
|
||||
|
||||
Reference in New Issue
Block a user