pleroma/lib/pleroma/web/feed/tag_controller.ex

40 lines
1.2 KiB
Elixir
Raw Normal View History

2019-12-06 07:32:29 +01:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
2019-12-06 07:32:29 +01:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Feed.TagController do
use Pleroma.Web, :controller
alias Pleroma.Config
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.Feed.FeedView
2019-12-17 20:13:45 +01:00
def feed(conn, %{"tag" => raw_tag} = params) do
2020-01-24 20:08:10 +01:00
{format, tag} = parse_tag(raw_tag)
2019-12-17 20:13:45 +01:00
2019-12-06 07:32:29 +01:00
activities =
%{"type" => ["Create"], "tag" => tag}
|> Pleroma.Maps.put_if_present("max_id", params["max_id"])
2019-12-06 07:32:29 +01:00
|> ActivityPub.fetch_public_activities()
conn
|> put_resp_content_type("application/#{format}+xml")
2019-12-06 07:32:29 +01:00
|> put_view(FeedView)
2020-01-24 20:08:10 +01:00
|> render("tag.#{format}",
2019-12-17 20:13:45 +01:00
activities: activities,
tag: tag,
feed_config: Config.get([:feed])
)
2019-12-06 07:32:29 +01:00
end
2020-01-24 20:08:10 +01:00
@spec parse_tag(binary() | any()) :: {format :: String.t(), tag :: String.t()}
2019-12-06 07:32:29 +01:00
defp parse_tag(raw_tag) when is_binary(raw_tag) do
case Enum.reverse(String.split(raw_tag, ".")) do
2020-01-24 20:08:10 +01:00
[format | tag] when format in ["atom", "rss"] -> {format, Enum.join(tag, ".")}
_ -> {"rss", raw_tag}
2019-12-06 07:32:29 +01:00
end
end
2020-01-24 20:08:10 +01:00
defp parse_tag(raw_tag), do: {"rss", raw_tag}
2019-12-06 07:32:29 +01:00
end