2019-02-27 15:28:09 +00:00
|
|
|
defmodule MobilizonWeb.FeedController do
|
|
|
|
@moduledoc """
|
|
|
|
Controller to serve RSS, ATOM and iCal Feeds
|
|
|
|
"""
|
|
|
|
use MobilizonWeb, :controller
|
2019-07-08 14:53:54 +00:00
|
|
|
plug(:put_layout, false)
|
2019-04-30 12:21:33 +00:00
|
|
|
action_fallback(MobilizonWeb.FallbackController)
|
2019-02-27 15:28:09 +00:00
|
|
|
|
2019-03-01 11:57:22 +00:00
|
|
|
def actor(conn, %{"name" => name, "format" => "atom"}) do
|
2019-07-23 16:06:22 +00:00
|
|
|
case Cachex.fetch(:feed, "actor_" <> name) do
|
2019-09-17 21:39:26 +00:00
|
|
|
{:commit, data} ->
|
2019-07-23 16:06:22 +00:00
|
|
|
conn
|
|
|
|
|> put_resp_content_type("application/atom+xml")
|
|
|
|
|> send_resp(200, data)
|
|
|
|
|
2019-09-17 21:39:26 +00:00
|
|
|
_ ->
|
2019-04-30 12:21:33 +00:00
|
|
|
{:error, :not_found}
|
2019-02-27 15:28:09 +00:00
|
|
|
end
|
|
|
|
end
|
2019-03-06 16:07:42 +00:00
|
|
|
|
|
|
|
def actor(conn, %{"name" => name, "format" => "ics"}) do
|
2019-07-23 16:06:22 +00:00
|
|
|
case Cachex.fetch(:ics, "actor_" <> name) do
|
2019-09-17 21:39:26 +00:00
|
|
|
{:commit, data} ->
|
2019-07-23 16:06:22 +00:00
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/calendar")
|
|
|
|
|> send_resp(200, data)
|
|
|
|
|
2019-09-17 21:39:26 +00:00
|
|
|
_ ->
|
2019-04-30 12:21:33 +00:00
|
|
|
{:error, :not_found}
|
2019-03-06 16:07:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def event(conn, %{"uuid" => uuid, "format" => "ics"}) do
|
2019-07-23 16:06:22 +00:00
|
|
|
case Cachex.fetch(:ics, "event_" <> uuid) do
|
2019-09-17 21:39:26 +00:00
|
|
|
{:commit, data} ->
|
2019-07-23 16:06:22 +00:00
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/calendar")
|
|
|
|
|> send_resp(200, data)
|
|
|
|
|
2019-09-17 21:39:26 +00:00
|
|
|
_ ->
|
2019-04-30 12:21:33 +00:00
|
|
|
{:error, :not_found}
|
2019-03-06 16:07:42 +00:00
|
|
|
end
|
|
|
|
end
|
2019-03-08 11:25:06 +00:00
|
|
|
|
|
|
|
def going(conn, %{"token" => token, "format" => "ics"}) do
|
2019-07-23 16:06:22 +00:00
|
|
|
case Cachex.fetch(:ics, "token_" <> token) do
|
2019-09-17 21:39:26 +00:00
|
|
|
{:commit, data} ->
|
2019-07-23 16:06:22 +00:00
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/calendar")
|
|
|
|
|> send_resp(200, data)
|
|
|
|
|
2019-09-17 21:39:26 +00:00
|
|
|
_ ->
|
2019-04-30 12:21:33 +00:00
|
|
|
{:error, :not_found}
|
2019-03-08 11:25:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def going(conn, %{"token" => token, "format" => "atom"}) do
|
2019-07-23 16:06:22 +00:00
|
|
|
case Cachex.fetch(:feed, "token_" <> token) do
|
2019-09-17 21:39:26 +00:00
|
|
|
{:commit, data} ->
|
2019-07-23 16:06:22 +00:00
|
|
|
conn
|
|
|
|
|> put_resp_content_type("application/atom+xml")
|
|
|
|
|> send_resp(200, data)
|
|
|
|
|
2019-09-17 21:39:26 +00:00
|
|
|
{:ignore, _} ->
|
2019-04-30 12:21:33 +00:00
|
|
|
{:error, :not_found}
|
2019-03-08 11:25:06 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-27 15:28:09 +00:00
|
|
|
end
|