@@ -189,7 +189,7 @@ defmodule Mobilizon.Federation.WebFinger do
|
||||
{:ok, String.t()} | {:error, :link_not_found} | {:error, any()}
|
||||
defp find_webfinger_endpoint(domain) when is_binary(domain) do
|
||||
with {:ok, %Tesla.Env{status: 200, body: body}} <-
|
||||
fetch_document("http://#{domain}/.well-known/host-meta"),
|
||||
HostMetaClient.get("http://#{domain}/.well-known/host-meta"),
|
||||
link_template when is_binary(link_template) <- find_link_from_template(body) do
|
||||
{:ok, link_template}
|
||||
else
|
||||
@@ -258,11 +258,6 @@ defmodule Mobilizon.Federation.WebFinger do
|
||||
{:error, :link_not_found}
|
||||
end
|
||||
|
||||
@spec fetch_document(String.t()) :: Tesla.Env.result()
|
||||
defp fetch_document(endpoint) do
|
||||
with {:error, err} <- HostMetaClient.get(endpoint), do: {:error, err}
|
||||
end
|
||||
|
||||
@spec address_invalid(String.t()) :: false | {:error, :invalid_address}
|
||||
defp address_invalid(address) do
|
||||
with %URI{host: host, scheme: scheme} <- URI.parse(address),
|
||||
|
||||
@@ -39,9 +39,7 @@ defmodule Mobilizon.Federation.WebFinger.XmlBuilder do
|
||||
defp to_xml(content) when is_binary(content), do: to_string(content)
|
||||
|
||||
defp to_xml(content) when is_list(content) do
|
||||
content
|
||||
|> Enum.map(&to_xml/1)
|
||||
|> Enum.join()
|
||||
Enum.map_join(content, &to_xml/1)
|
||||
end
|
||||
|
||||
defp to_xml(%NaiveDateTime{} = time), do: NaiveDateTime.to_iso8601(time)
|
||||
@@ -49,9 +47,7 @@ defmodule Mobilizon.Federation.WebFinger.XmlBuilder do
|
||||
@spec make_open_tag(tag :: atom, attributes :: map()) :: String.t()
|
||||
defp make_open_tag(tag, attributes) do
|
||||
attributes_string =
|
||||
attributes
|
||||
|> Enum.map(fn {attribute, value} -> "#{attribute}=\"#{value}\"" end)
|
||||
|> Enum.join(" ")
|
||||
Enum.map_join(attributes, " ", fn {attribute, value} -> "#{attribute}=\"#{value}\"" end)
|
||||
|
||||
[to_string(tag), attributes_string] |> Enum.join(" ") |> String.trim()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user