Use a RichMediaPreviewClient to get details on resources

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-10-20 09:25:02 +02:00
parent 4617c51e52
commit 9966469444
2 changed files with 25 additions and 1 deletions

View File

@ -0,0 +1,23 @@
defmodule Mobilizon.Service.HTTP.RichMediaPreviewClient do
@moduledoc """
Tesla HTTP Basic Client
with JSON middleware
"""
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

View File

@ -17,6 +17,7 @@ defmodule Mobilizon.Service.RichMedia.Parser do
]
alias Mobilizon.Config
alias Mobilizon.Service.HTTP.RichMediaPreviewClient
alias Mobilizon.Service.RichMedia.Favicon
alias Plug.Conn.Utils
require Logger
@ -56,7 +57,7 @@ defmodule Mobilizon.Service.RichMedia.Parser do
with {:ok, _} <- prevent_local_address(url),
{:ok, %{body: body, status: code, headers: response_headers}}
when code in 200..299 <-
Tesla.get(
RichMediaPreviewClient.get(
url,
headers: headers,
opts: @options