2019-02-27 16:28:09 +01:00
|
|
|
defmodule MobilizonWeb.FeedController do
|
|
|
|
@moduledoc """
|
|
|
|
Controller to serve RSS, ATOM and iCal Feeds
|
|
|
|
"""
|
|
|
|
use MobilizonWeb, :controller
|
|
|
|
|
2019-03-01 12:57:22 +01:00
|
|
|
def actor(conn, %{"name" => name, "format" => "atom"}) do
|
2019-02-27 16:28:09 +01:00
|
|
|
with {status, data} when status in [:ok, :commit] <-
|
2019-03-01 12:57:22 +01:00
|
|
|
Cachex.fetch(:feed, "actor_" <> name) do
|
2019-02-27 16:28:09 +01:00
|
|
|
conn
|
|
|
|
|> put_resp_content_type("application/atom+xml")
|
|
|
|
|> send_resp(200, data)
|
|
|
|
else
|
|
|
|
_err ->
|
2019-03-01 12:57:22 +01:00
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/html")
|
|
|
|
|> send_file(404, "priv/static/index.html")
|
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
|
|
|
|
with {status, data} when status in [:ok, :commit] <-
|
|
|
|
Cachex.fetch(:ics, "actor_" <> name) do
|
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/calendar")
|
|
|
|
|> send_resp(200, data)
|
|
|
|
else
|
|
|
|
_err ->
|
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/html")
|
|
|
|
|> send_file(404, "priv/static/index.html")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def event(conn, %{"uuid" => uuid, "format" => "ics"}) do
|
|
|
|
with {status, data} when status in [:ok, :commit] <-
|
|
|
|
Cachex.fetch(:ics, "event_" <> uuid) do
|
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/calendar")
|
|
|
|
|> send_resp(200, data)
|
|
|
|
else
|
|
|
|
_err ->
|
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/html")
|
|
|
|
|> send_file(404, "priv/static/index.html")
|
|
|
|
end
|
|
|
|
end
|
2019-02-27 16:28:09 +01:00
|
|
|
end
|