2019-12-06 06:32:29 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-12-06 06:32:29 +00: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
|
|
|
|
|
2020-08-31 20:58:21 +00:00
|
|
|
def feed(conn, params) do
|
2020-10-05 20:48:00 +00:00
|
|
|
if Config.get!([:instance, :public]) do
|
2020-08-31 20:58:21 +00:00
|
|
|
render_feed(conn, params)
|
|
|
|
else
|
|
|
|
render_error(conn, :not_found, "Not found")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-02 19:18:02 +00:00
|
|
|
defp render_feed(conn, %{"tag" => raw_tag} = params) do
|
2020-01-24 19:08:10 +00:00
|
|
|
{format, tag} = parse_tag(raw_tag)
|
2019-12-17 19:13:45 +00:00
|
|
|
|
2019-12-06 06:32:29 +00:00
|
|
|
activities =
|
2020-06-04 17:33:16 +00:00
|
|
|
%{type: ["Create"], tag: tag}
|
2020-06-05 19:15:10 +00:00
|
|
|
|> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
|
2019-12-06 06:32:29 +00:00
|
|
|
|> ActivityPub.fetch_public_activities()
|
|
|
|
|
|
|
|
conn
|
2020-03-13 14:58:14 +00:00
|
|
|
|> put_resp_content_type("application/#{format}+xml")
|
2019-12-06 06:32:29 +00:00
|
|
|
|> put_view(FeedView)
|
2020-01-24 19:08:10 +00:00
|
|
|
|> render("tag.#{format}",
|
2019-12-17 19:13:45 +00:00
|
|
|
activities: activities,
|
|
|
|
tag: tag,
|
|
|
|
feed_config: Config.get([:feed])
|
|
|
|
)
|
2019-12-06 06:32:29 +00:00
|
|
|
end
|
|
|
|
|
2020-01-24 19:08:10 +00:00
|
|
|
@spec parse_tag(binary() | any()) :: {format :: String.t(), tag :: String.t()}
|
2020-10-05 20:48:00 +00:00
|
|
|
defp parse_tag(raw_tag) do
|
|
|
|
case is_binary(raw_tag) && Enum.reverse(String.split(raw_tag, ".")) do
|
|
|
|
[format | tag] when format in ["rss", "atom"] ->
|
|
|
|
{format, Enum.join(tag, ".")}
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
{"atom", raw_tag}
|
2019-12-06 06:32:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|