mobilizon/lib/web/controllers/feed_controller.ex

69 lines
1.8 KiB
Elixir
Raw Normal View History

2020-01-26 21:36:50 +01:00
defmodule Mobilizon.Web.FeedController do
@moduledoc """
Controller to serve RSS, ATOM and iCal Feeds
"""
2020-01-26 21:36:50 +01:00
use Mobilizon.Web, :controller
plug(:put_layout, false)
2020-01-26 21:36:50 +01:00
action_fallback(Mobilizon.Web.FallbackController)
def actor(conn, %{"name" => name, "format" => "atom"}) do
case Cachex.fetch(:feed, "actor_" <> name) do
{status, data} when status in [:commit, :ok] ->
conn
|> put_resp_content_type("application/atom+xml")
|> send_resp(200, data)
2019-09-17 23:39:26 +02:00
_ ->
{:error, :not_found}
end
end
def actor(conn, %{"name" => name, "format" => "ics"}) do
case Cachex.fetch(:ics, "actor_" <> name) do
{status, data} when status in [:commit, :ok] ->
conn
|> put_resp_content_type("text/calendar")
|> send_resp(200, data)
_err ->
{:error, :not_found}
end
end
def event(conn, %{"uuid" => uuid, "format" => "ics"}) do
case Cachex.fetch(:ics, "event_" <> uuid) do
{status, data} when status in [:commit, :ok] ->
conn
|> put_resp_content_type("text/calendar")
|> send_resp(200, data)
2019-09-17 23:39:26 +02:00
_ ->
{:error, :not_found}
end
end
def going(conn, %{"token" => token, "format" => "ics"}) do
case Cachex.fetch(:ics, "token_" <> token) do
{status, data} when status in [:commit, :ok] ->
conn
|> put_resp_content_type("text/calendar")
|> send_resp(200, data)
2019-09-17 23:39:26 +02:00
_ ->
{:error, :not_found}
end
end
def going(conn, %{"token" => token, "format" => "atom"}) do
case Cachex.fetch(:feed, "token_" <> token) do
{status, data} when status in [:commit, :ok] ->
conn
|> put_resp_content_type("application/atom+xml")
|> send_resp(200, data)
2019-09-17 23:39:26 +02:00
{:ignore, _} ->
{:error, :not_found}
end
end
end