forked from potsda.mn/mobilizon
Use a RichMediaPreviewClient to get details on resources
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
23dcb47ce5
commit
efd95044c2
23
lib/service/http/rich_media_preview_client.ex
Normal file
23
lib/service/http/rich_media_preview_client.ex
Normal 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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue