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 23dcb47ce5
commit efd95044c2
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
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.Config
alias Mobilizon.Service.HTTP.RichMediaPreviewClient
alias Mobilizon.Service.RichMedia.Favicon alias Mobilizon.Service.RichMedia.Favicon
alias Plug.Conn.Utils alias Plug.Conn.Utils
require Logger require Logger
@ -56,7 +57,7 @@ defmodule Mobilizon.Service.RichMedia.Parser do
with {:ok, _} <- prevent_local_address(url), with {:ok, _} <- prevent_local_address(url),
{:ok, %{body: body, status: code, headers: response_headers}} {:ok, %{body: body, status: code, headers: response_headers}}
when code in 200..299 <- when code in 200..299 <-
Tesla.get( RichMediaPreviewClient.get(
url, url,
headers: headers, headers: headers,
opts: @options opts: @options