1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Feed.TagController do
6 use Pleroma.Web, :controller
9 alias Pleroma.Web.ActivityPub.ActivityPub
10 alias Pleroma.Web.Feed.FeedView
12 def feed(conn, params) do
13 unless Pleroma.Config.restrict_unauthenticated_access?(:activities, :local) do
14 render_feed(conn, params)
16 render_error(conn, :not_found, "Not found")
20 def render_feed(conn, %{"tag" => raw_tag} = params) do
21 {format, tag} = parse_tag(raw_tag)
24 %{type: ["Create"], tag: tag}
25 |> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
26 |> ActivityPub.fetch_public_activities()
29 |> put_resp_content_type("application/#{format}+xml")
31 |> render("tag.#{format}",
32 activities: activities,
34 feed_config: Config.get([:feed])
38 @spec parse_tag(binary() | any()) :: {format :: String.t(), tag :: String.t()}
39 defp parse_tag(raw_tag) when is_binary(raw_tag) do
40 case Enum.reverse(String.split(raw_tag, ".")) do
41 [format | tag] when format in ["atom", "rss"] -> {format, Enum.join(tag, ".")}
46 defp parse_tag(raw_tag), do: {"rss", raw_tag}