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