Create AdminAPI.InstanceController
[akkoma] / lib / pleroma / web / admin_api / controllers / instance_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.AdminAPI.InstanceController do
6 use Pleroma.Web, :controller
7
8 import Pleroma.Web.ControllerHelper, only: [fetch_integer_param: 3]
9
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.AdminAPI
12 alias Pleroma.Web.Plugs.OAuthScopesPlug
13
14 require Logger
15
16 @default_page_size 50
17
18 plug(
19 OAuthScopesPlug,
20 %{scopes: ["admin:read:statuses"]}
21 when action in [:list_instance_statuses]
22 )
23
24 action_fallback(AdminAPI.FallbackController)
25
26 def list_instance_statuses(conn, %{"instance" => instance} = params) do
27 with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true
28 {page, page_size} = page_params(params)
29
30 result =
31 ActivityPub.fetch_statuses(nil, %{
32 instance: instance,
33 limit: page_size,
34 offset: (page - 1) * page_size,
35 exclude_reblogs: not with_reblogs,
36 total: true
37 })
38
39 conn
40 |> put_view(AdminAPI.StatusView)
41 |> render("index.json", %{total: result[:total], activities: result[:items], as: :activity})
42 end
43
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