Add Gemini protocol scrape stage

This commit is contained in:
Shadowfacts 2020-07-18 19:50:41 -04:00
parent 4f16933198
commit 12bb742be9
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,37 @@
defmodule Frenzy.Pipeline.GeminiScrapeStage do
require Logger
alias Frenzy.Network
alias Frenzy.Pipeline.Stage
@behaviour Stage
@impl Stage
def apply(opts, %{url: url} = item_params) do
case get_content(url, opts) do
{:error, reason} ->
Logger.warn("Unable to get Gemini content for #{url}: #{reason}")
{:ok, item_params}
content ->
{:ok, %{item_params | content: content}}
end
end
@impl Stage
def validate_opts(opts) do
{:ok, opts}
end
@impl Stage
def default_opts(), do: %{}
@spec get_content(String.t(), map()) :: {:ok, String.t()} | {:error, term()}
def get_content(url, _opts) do
case Network.gemini_request(url) do
{:error, reason} ->
{:error, reason}
{:ok, %Gemini.Response{body: body}} ->
body
end
end
end

View File

@ -30,6 +30,9 @@ defmodule Frenzy.UpdateFeeds do
{:noreply, state}
end
# workaround for unhanled {:ssl_closed, {:sslsocket, {:gen_tcp, ...}}} message when Gemini module
def handle_info({:ssl_closed, _}, state), do: {:noreply, state}
defp schedule_update() do
# 30 minutes
Process.send_after(self(), :update_feeds, 30 * 60 * 1000)

View File

@ -6,7 +6,8 @@ defmodule FrenzyWeb.EditPipelineLive do
@stages [
{"Filter Stage", "Frenzy.Pipeline.FilterStage"},
{"Scrape Stage", "Frenzy.Pipeline.ScrapeStage"},
{"Conditional Stage", "Frenzy.Pipeline.ConditionalStage"}
{"Conditional Stage", "Frenzy.Pipeline.ConditionalStage"},
{"Gemini Scrape Stage", "Frenzy.Pipeline.GeminiScrapeStage"}
]
def stages, do: @stages