logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

tag_controller.ex (1334B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Feed.TagController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.Config
  7. alias Pleroma.Web.ActivityPub.ActivityPub
  8. alias Pleroma.Web.Feed.FeedView
  9. def feed(conn, params) do
  10. if Config.get!([:instance, :public]) do
  11. render_feed(conn, params)
  12. else
  13. render_error(conn, :not_found, "Not found")
  14. end
  15. end
  16. defp render_feed(conn, %{"tag" => raw_tag} = params) do
  17. {format, tag} = parse_tag(raw_tag)
  18. activities =
  19. %{type: ["Create"], tag: tag}
  20. |> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
  21. |> ActivityPub.fetch_public_activities()
  22. conn
  23. |> put_resp_content_type("application/#{format}+xml")
  24. |> put_view(FeedView)
  25. |> render("tag.#{format}",
  26. activities: activities,
  27. tag: tag,
  28. feed_config: Config.get([:feed])
  29. )
  30. end
  31. @spec parse_tag(binary() | any()) :: {format :: String.t(), tag :: String.t()}
  32. defp parse_tag(raw_tag) do
  33. case is_binary(raw_tag) && Enum.reverse(String.split(raw_tag, ".")) do
  34. [format | tag] when format in ["rss", "atom"] ->
  35. {format, Enum.join(tag, ".")}
  36. _ ->
  37. {"atom", raw_tag}
  38. end
  39. end
  40. end