1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.RelMe do
12 if Mix.env() == :test do
13 def parse(url) when is_binary(url), do: parse_url(url)
15 def parse(url) when is_binary(url) do
16 Cachex.fetch!(:rel_me_cache, url, fn _ ->
17 {:commit, parse_url(url)}
20 e -> {:error, "Cachex error: #{inspect(e)}"}
24 def parse(_), do: {:error, "No URL provided"}
26 defp parse_url(url) do
27 {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options)
30 Floki.attribute(html, "link[rel~=me]", "href") ++
31 Floki.attribute(html, "a[rel~=me]", "href")
35 e -> {:error, "Parsing error: #{inspect(e)}"}
38 def maybe_put_rel_me("http" <> _ = target_page, profile_urls) when is_list(profile_urls) do
39 {:ok, rel_me_hrefs} = parse(target_page)
41 true = Enum.any?(rel_me_hrefs, fn x -> x in profile_urls end)
48 def maybe_put_rel_me(_, _) do