Add option to disable remote scraping for feeds
This commit is contained in:
parent
d3d5e28b4e
commit
24c942c5d2
|
@ -35,6 +35,7 @@ defmodule Frenzy.Feed do
|
||||||
field :site_url, :string
|
field :site_url, :string
|
||||||
field :title, :string
|
field :title, :string
|
||||||
field :filter_enabled, :boolean
|
field :filter_enabled, :boolean
|
||||||
|
field :scrape_remote_content, :boolean
|
||||||
|
|
||||||
belongs_to :group, Frenzy.Group
|
belongs_to :group, Frenzy.Group
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ defmodule Frenzy.Feed do
|
||||||
@doc false
|
@doc false
|
||||||
def changeset(feed, attrs) do
|
def changeset(feed, attrs) do
|
||||||
feed
|
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)
|
|> cast_assoc(:filter, required: true)
|
||||||
|> validate_required([:feed_url, :filter])
|
|> validate_required([:feed_url, :filter])
|
||||||
end
|
end
|
||||||
|
|
|
@ -124,13 +124,17 @@ defmodule Frenzy.UpdateFeeds do
|
||||||
Logger.debug("Creating item for #{url}")
|
Logger.debug("Creating item for #{url}")
|
||||||
|
|
||||||
content =
|
content =
|
||||||
case get_article_content(url) do
|
if feed.scrape_remote_content do
|
||||||
{:ok, content} ->
|
case get_article_content(url) do
|
||||||
content
|
{:ok, content} ->
|
||||||
|
content
|
||||||
|
|
||||||
{:err, reason} ->
|
{:err, reason} ->
|
||||||
Logger.warn("Unable to fetch article for #{url}: #{inspect(reason)}")
|
Logger.warn("Unable to fetch article for #{url}: #{inspect(reason)}")
|
||||||
entry.description
|
entry.description
|
||||||
|
end
|
||||||
|
else
|
||||||
|
entry.description
|
||||||
end
|
end
|
||||||
|
|
||||||
item_params = %{
|
item_params = %{
|
||||||
|
|
|
@ -52,6 +52,19 @@ defmodule FrenzyWeb.FeedController do
|
||||||
redirect(conn, to: Routes.group_path(Endpoint, :show, group_id))
|
redirect(conn, to: Routes.group_path(Endpoint, :show, group_id))
|
||||||
end
|
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
|
def delete(conn, _params) do
|
||||||
feed = conn.assigns[:feed]
|
feed = conn.assigns[:feed]
|
||||||
{:ok, _} = Repo.delete(feed)
|
{:ok, _} = Repo.delete(feed)
|
||||||
|
|
|
@ -47,10 +47,10 @@ defmodule FrenzyWeb.Router do
|
||||||
get "/", GroupController, :index
|
get "/", GroupController, :index
|
||||||
resources "/groups", GroupController, except: [:edit, :update]
|
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/refresh", FeedController, :refresh
|
||||||
post "/feeds/:id/enable_filter", FeedController, :enable_filter
|
#post "/feeds/:id/enable_filter", FeedController, :enable_filter
|
||||||
post "/feeds/:id/disable_filter", FeedController, :disable_filter
|
#post "/feeds/:id/disable_filter", FeedController, :disable_filter
|
||||||
|
|
||||||
resources "/filters", FilterController, only: [:edit, :update]
|
resources "/filters", FilterController, only: [:edit, :update]
|
||||||
post "/filters/:id/add_rule", FilterController, :add_rule
|
post "/filters/:id/add_rule", FilterController, :add_rule
|
||||||
|
|
|
@ -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 %>
|
|
@ -4,25 +4,12 @@
|
||||||
<%= submit "Refresh Feed", class: "btn btn-primary" %>
|
<%= submit "Refresh Feed", class: "btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= if @feed.filter_enabled do %>
|
<a class="btn btn-primary" href="<%= Routes.feed_path(@conn, :edit, @feed.id) %>">Edit Feed</a>
|
||||||
<%= 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 %>
|
|
||||||
|
|
||||||
<%= form_tag Routes.feed_path(@conn, :delete, @feed.id), method: :delete, class: "d-inline" do %>
|
<%= form_tag Routes.feed_path(@conn, :delete, @feed.id), method: :delete, class: "d-inline" do %>
|
||||||
<%= submit "Delete Feed", class: "btn btn-danger" %>
|
<%= submit "Delete Feed", class: "btn btn-danger" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
<h3 class="mt-4">Items</h3>
|
<h3 class="mt-4">Items</h3>
|
||||||
|
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue