logo

pleroma

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

tag_controller.ex (1470B)


  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 not Config.restrict_unauthenticated_access?(:timelines, :local) 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. local_only = Config.restrict_unauthenticated_access?(:timelines, :federated)
  18. {format, tag} = parse_tag(raw_tag)
  19. activities =
  20. %{type: ["Create"], tag: tag, local_only: local_only}
  21. |> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
  22. |> ActivityPub.fetch_public_activities()
  23. conn
  24. |> put_resp_content_type("application/#{format}+xml")
  25. |> put_view(FeedView)
  26. |> render("tag.#{format}",
  27. activities: activities,
  28. tag: tag,
  29. feed_config: Config.get([:feed])
  30. )
  31. end
  32. @spec parse_tag(binary() | any()) :: {format :: String.t(), tag :: String.t()}
  33. defp parse_tag(raw_tag) do
  34. case is_binary(raw_tag) && Enum.reverse(String.split(raw_tag, ".")) do
  35. [format | tag] when format in ["rss", "atom"] ->
  36. {format, Enum.join(tag, ".")}
  37. _ ->
  38. {"atom", raw_tag}
  39. end
  40. end
  41. end