Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

88 行
2.7KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Feed.UserController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.User
  7. alias Pleroma.Web.ActivityPub.ActivityPub
  8. alias Pleroma.Web.ActivityPub.ActivityPubController
  9. alias Pleroma.Web.Feed.FeedView
  10. plug(Pleroma.Web.Plugs.SetFormatPlug when action in [:feed_redirect])
  11. action_fallback(:errors)
  12. def feed_redirect(%{assigns: %{format: "html"}} = conn, %{"nickname" => nickname}) do
  13. with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname_or_id(nickname)} do
  14. Pleroma.Web.Fallback.RedirectController.redirector_with_meta(conn, %{user: user})
  15. end
  16. end
  17. def feed_redirect(%{assigns: %{format: format}} = conn, _params)
  18. when format in ["json", "activity+json"] do
  19. with %{halted: false} = conn <-
  20. Pleroma.Web.Plugs.EnsureAuthenticatedPlug.call(conn,
  21. unless_func: &Pleroma.Web.Plugs.FederatingPlug.federating?/1
  22. ) do
  23. ActivityPubController.call(conn, :user)
  24. end
  25. end
  26. def feed_redirect(conn, %{"nickname" => nickname}) do
  27. with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
  28. redirect(conn, external: "#{user_feed_url(conn, :feed, user.nickname)}.atom")
  29. end
  30. end
  31. def feed(conn, params) do
  32. unless Pleroma.Config.restrict_unauthenticated_access?(:profiles, :local) do
  33. render_feed(conn, params)
  34. else
  35. errors(conn, {:error, :not_found})
  36. end
  37. end
  38. def render_feed(conn, %{"nickname" => nickname} = params) do
  39. format = get_format(conn)
  40. format =
  41. if format in ["rss", "atom"] do
  42. format
  43. else
  44. "atom"
  45. end
  46. with {_, %User{local: true} = user} <- {:fetch_user, User.get_cached_by_nickname(nickname)} do
  47. activities =
  48. %{
  49. type: ["Create"],
  50. actor_id: user.ap_id
  51. }
  52. |> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
  53. |> ActivityPub.fetch_public_or_unlisted_activities()
  54. conn
  55. |> put_resp_content_type("application/#{format}+xml")
  56. |> put_view(FeedView)
  57. |> render("user.#{format}",
  58. user: user,
  59. activities: activities,
  60. feed_config: Pleroma.Config.get([:feed])
  61. )
  62. end
  63. end
  64. def errors(conn, {:error, :not_found}) do
  65. render_error(conn, :not_found, "Not found")
  66. end
  67. def errors(conn, {:fetch_user, %User{local: false}}), do: errors(conn, {:error, :not_found})
  68. def errors(conn, {:fetch_user, nil}), do: errors(conn, {:error, :not_found})
  69. def errors(conn, _) do
  70. render_error(conn, :internal_server_error, "Something went wrong")
  71. end
  72. end