Add OPML export

This commit is contained in:
Shadowfacts 2019-08-30 19:44:51 -04:00
parent 1015fd5162
commit b559bd9dc3
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
5 changed files with 43 additions and 1 deletions

View File

@ -0,0 +1,32 @@
defmodule Frenzy.OPML.Exporter do
import XmlBuilder
@spec export([Frenzy.Group.t()]) :: String.t()
def export(groups) do
element(:opml, %{version: "1.0"}, [
element(:head, %{}, [
element(:title, "Frenzy export")
]),
element(
:body,
%{},
Enum.map(groups, fn group ->
element(
:outline,
%{text: group.title, title: group.title},
Enum.map(group.feeds, fn feed ->
element(:outline, %{
type: "rss",
text: feed.title,
title: feed.title,
xmlUrl: feed.feed_url,
htmlUrl: feed.site_url
})
end)
)
end)
)
])
|> generate()
end
end

View File

@ -146,4 +146,10 @@ defmodule FrenzyWeb.AccountController do
)
|> redirect(to: Routes.group_path(Endpoint, :index))
end
def export(conn, _params) do
user = conn.assigns[:user] |> Repo.preload(:groups)
opml = Frenzy.OPML.Exporter.export(user.groups)
send_download(conn, {:binary, opml}, filename: "frenzy_export.opml")
end
end

View File

@ -44,6 +44,7 @@ defmodule FrenzyWeb.Router do
post "/account/change_fever_password", AccountController, :do_change_fever_password
post "/account/remove_client", AccountController, :remove_client
post "/account/import", AccountController, :import
post "/account/export", AccountController, :export
get "/", GroupController, :index
resources "/groups", GroupController, except: [:edit, :update]

View File

@ -11,6 +11,9 @@
<%= file_input f, :file %>
<%= submit "Import OPML", class: "btn btn-primary" %>
<% end %>
<%= form_for @conn, Routes.account_path(@conn, :export), [method: :post, class: "mt-2"], fn f -> %>
<%= submit "Export OPML", class: "btn btn-primary" %>
<% end %>
</section>
<section class="mt-4">

View File

@ -48,7 +48,7 @@ defmodule Frenzy.MixProject do
{:timex, "~> 3.0"},
{:readability, git: "https://github.com/shadowfacts/readability.git", branch: "master"},
{:bcrypt_elixir, "~> 2.0"},
{:dialyxir, "~> 1.0.0-rc.6"},
{:dialyxir, "~> 1.0.0-rc.6", only: :dev, runtime: false},
{:xml_builder, "~> 2.1.1"}
]
end