diff options
author | lain <lain@soykaf.club> | 2020-09-07 15:00:14 +0200 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-09-07 15:00:14 +0200 |
commit | d00f74e036735c1c238f661076f2925b39daa6ac (patch) | |
tree | d70d9fcfb1b815406b739ac5b012846fd0622a2f /lib/pleroma/html.ex | |
parent | bb007b9298b514c305dff944bef8463ffe1596a8 (diff) | |
parent | 6c6de8e5dfaf245e4e16ddca0c741342eeaa9187 (diff) | |
download | pleroma-matrix-explorations.tar.gz |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into matrix-explorationsmatrix-explorations
Diffstat (limited to 'lib/pleroma/html.ex')
-rw-r--r-- | lib/pleroma/html.ex | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 20b02f091..43e9145be 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -100,21 +100,27 @@ defmodule Pleroma.HTML do end) end - def extract_first_external_url(_, nil), do: {:error, "No content"} + def extract_first_external_url_from_object(%{data: %{"content" => content}} = object) + when is_binary(content) do + unless object.data["fake"] do + key = "URL|#{object.id}" + + Cachex.fetch!(:scrubber_cache, key, fn _key -> + {:commit, {:ok, extract_first_external_url(content)}} + end) + else + {:ok, extract_first_external_url(content)} + end + end - def extract_first_external_url(object, content) do - key = "URL|#{object.id}" + def extract_first_external_url_from_object(_), do: {:error, :no_content} - Cachex.fetch!(:scrubber_cache, key, fn _key -> - result = - content - |> Floki.parse_fragment!() - |> Floki.find("a:not(.mention,.hashtag,.attachment,[rel~=\"tag\"])") - |> Enum.take(1) - |> Floki.attribute("href") - |> Enum.at(0) - - {:commit, {:ok, result}} - end) + def extract_first_external_url(content) do + content + |> Floki.parse_fragment!() + |> Floki.find("a:not(.mention,.hashtag,.attachment,[rel~=\"tag\"])") + |> Enum.take(1) + |> Floki.attribute("href") + |> Enum.at(0) end end |