Don't fetch favicon for Gemini protocol feeds

This commit is contained in:
Shadowfacts 2020-07-18 22:13:51 -04:00
parent 12bb742be9
commit 198ca0345b
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 18 additions and 15 deletions

View File

@ -13,28 +13,31 @@ defmodule Frenzy.Task.FetchFavicon do
site_url = site_url =
case feed.site_url do case feed.site_url do
url when is_binary(url) -> url when is_binary(url) ->
url URI.parse(url)
_ -> _ ->
%URI{URI.parse(feed.feed_url) | path: nil, query: nil, fragment: nil} |> URI.to_string() %URI{URI.parse(feed.feed_url) | path: nil, query: nil, fragment: nil}
end end
Logger.debug("Fetching favicon for #{site_url}") if site_url.scheme in ["http", "https"] do
Logger.debug("Fetching favicon for #{site_url}")
favicon_url = fetch_favicon_url_from_webpage(site_url) || URI.merge(site_url, "/favicon.ico") favicon_url =
fetch_favicon_url_from_webpage(site_url) || URI.merge(site_url, "/favicon.ico")
with %Feed{favicon_url: old_url} when old_url != favicon_url <- feed, with %Feed{favicon_url: old_url} when old_url != favicon_url <- feed,
{:ok, favicon_data} <- fetch_favicon_data(favicon_url) do {:ok, favicon_data} <- fetch_favicon_data(favicon_url) do
changeset = changeset =
Feed.changeset(feed, %{ Feed.changeset(feed, %{
favicon: favicon_data, favicon: favicon_data,
favicon_url: to_string(favicon_url) favicon_url: to_string(favicon_url)
}) })
{:ok, _feed} = Repo.update(changeset) {:ok, _feed} = Repo.update(changeset)
else else
_ -> _ ->
:ok :ok
end
end end
end end