logo

pleroma

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

instance_controller.ex (1690B)


  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.AdminAPI.InstanceController do
  5. use Pleroma.Web, :controller
  6. import Pleroma.Web.ControllerHelper, only: [fetch_integer_param: 3]
  7. alias Pleroma.Instances.Instance
  8. alias Pleroma.Web.ActivityPub.ActivityPub
  9. alias Pleroma.Web.AdminAPI
  10. alias Pleroma.Web.Plugs.OAuthScopesPlug
  11. require Logger
  12. @default_page_size 50
  13. plug(
  14. OAuthScopesPlug,
  15. %{scopes: ["admin:read:statuses"]}
  16. when action in [:list_statuses]
  17. )
  18. plug(
  19. OAuthScopesPlug,
  20. %{scopes: ["admin:write:accounts", "admin:write:statuses"]}
  21. when action in [:delete]
  22. )
  23. action_fallback(AdminAPI.FallbackController)
  24. def list_statuses(conn, %{"instance" => instance} = params) do
  25. with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true
  26. {page, page_size} = page_params(params)
  27. result =
  28. ActivityPub.fetch_statuses(nil, %{
  29. instance: instance,
  30. limit: page_size,
  31. offset: (page - 1) * page_size,
  32. exclude_reblogs: not with_reblogs,
  33. total: true
  34. })
  35. conn
  36. |> put_view(AdminAPI.StatusView)
  37. |> render("index.json", %{total: result[:total], activities: result[:items], as: :activity})
  38. end
  39. def delete(conn, %{"instance" => instance}) do
  40. with {:ok, _job} <- Instance.delete_users_and_activities(instance) do
  41. json(conn, instance)
  42. end
  43. end
  44. defp page_params(params) do
  45. {
  46. fetch_integer_param(params, "page", 1),
  47. fetch_integer_param(params, "page_size", @default_page_size)
  48. }
  49. end
  50. end