Add option to disable remote scraping for feeds

This commit is contained in:
Shadowfacts 2019-07-05 22:00:18 -04:00
parent d3d5e28b4e
commit 24c942c5d2
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
8 changed files with 64 additions and 25 deletions

View File

@ -35,6 +35,7 @@ defmodule Frenzy.Feed do
field :site_url, :string
field :title, :string
field :filter_enabled, :boolean
field :scrape_remote_content, :boolean
belongs_to :group, Frenzy.Group
@ -47,7 +48,7 @@ defmodule Frenzy.Feed do
@doc false
def changeset(feed, attrs) do
feed
|> cast(attrs, [:title, :feed_url, :site_url, :last_updated, :filter_enabled])
|> cast(attrs, [:title, :feed_url, :site_url, :last_updated, :filter_enabled, :scrape_remote_content])
|> cast_assoc(:filter, required: true)
|> validate_required([:feed_url, :filter])
end

View File

@ -124,13 +124,17 @@ defmodule Frenzy.UpdateFeeds do
Logger.debug("Creating item for #{url}")
content =
case get_article_content(url) do
{:ok, content} ->
content
if feed.scrape_remote_content do
case get_article_content(url) do
{:ok, content} ->
content
{:err, reason} ->
Logger.warn("Unable to fetch article for #{url}: #{inspect(reason)}")
entry.description
{:err, reason} ->
Logger.warn("Unable to fetch article for #{url}: #{inspect(reason)}")
entry.description
end
else
entry.description
end
item_params = %{

View File

@ -52,6 +52,19 @@ defmodule FrenzyWeb.FeedController do
redirect(conn, to: Routes.group_path(Endpoint, :show, group_id))
end
def edit(conn, _params) do
feed = conn.assigns[:feed] |> Repo.preload(:filter)
changeset = Feed.changeset(feed, %{})
render(conn, "edit.html", changeset: changeset)
end
def update(conn, %{"feed" => feed_params}) do
feed = conn.assigns[:feed] |> Repo.preload(:filter)
changeset = Feed.changeset(feed, feed_params)
{:ok, feed} = Repo.update(changeset)
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
end
def delete(conn, _params) do
feed = conn.assigns[:feed]
{:ok, _} = Repo.delete(feed)

View File

@ -47,10 +47,10 @@ defmodule FrenzyWeb.Router do
get "/", GroupController, :index
resources "/groups", GroupController, except: [:edit, :update]
resources "/feeds", FeedController, only: [:show, :create, :delete]
resources "/feeds", FeedController, except: [:index, :new]
post "/feeds/:id/refresh", FeedController, :refresh
post "/feeds/:id/enable_filter", FeedController, :enable_filter
post "/feeds/:id/disable_filter", FeedController, :disable_filter
#post "/feeds/:id/enable_filter", FeedController, :enable_filter
#post "/feeds/:id/disable_filter", FeedController, :disable_filter
resources "/filters", FilterController, only: [:edit, :update]
post "/filters/:id/add_rule", FilterController, :add_rule

View File

@ -0,0 +1,25 @@
<h2>Feed</h2>
<%= form_tag Routes.filter_path(@conn, :edit, @changeset.data.filter.id), method: :get, class: "d-inline" do %>
<%= submit "Edit Filter", class: "btn btn-secondary" %>
<% end %>
<%= form_for @changeset, Routes.feed_path(@conn, :update, @changeset.data.id), fn form -> %>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="filter_enabled">Filter Enabled</label>
<div class="col-sm-9">
<%= checkbox form, :filter_enabled %>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="scrape_remote_content">Scrape Remote Content</label>
<div class="col-sm-9">
<%= checkbox form, :scrape_remote_content %>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10">
<%= submit "Update Feed", class: "btn btn-primary" %>
</div>
</div>
<% end %>

View File

@ -4,25 +4,12 @@
<%= submit "Refresh Feed", class: "btn btn-primary" %>
<% end %>
<%= if @feed.filter_enabled do %>
<%= form_tag Routes.feed_path(@conn, :disable_filter, @feed.id), method: :post, class: "d-inline" do %>
<%= submit "Disable Filter", class: "btn btn-secondary" %>
<% end %>
<%= form_tag Routes.filter_path(@conn, :edit, @feed.filter.id), method: :get, class: "d-inline" do %>
<%= submit "Edit Filter", class: "btn btn-secondary" %>
<% end %>
<% else %>
<%= form_tag Routes.feed_path(@conn, :enable_filter, @feed.id), method: :post, class: "d-inline" do %>
<%= submit "Enable Filter", class: "btn btn-secondary" %>
<% end %>
<% end %>
<a class="btn btn-primary" href="<%= Routes.feed_path(@conn, :edit, @feed.id) %>">Edit Feed</a>
<%= form_tag Routes.feed_path(@conn, :delete, @feed.id), method: :delete, class: "d-inline" do %>
<%= submit "Delete Feed", class: "btn btn-danger" %>
<% end %>
<h3 class="mt-4">Items</h3>
<table class="table table-striped">

View File

@ -0,0 +1,9 @@
defmodule Frenzy.Repo.Migrations.FeedsAddScrapeRemoteContent do
use Ecto.Migration
def change do
alter table(:feeds) do
add :scrape_remote_content, :boolean, default: true
end
end
end