2021-07-17 12:05:25 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2021-07-17 12:05:25 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.AdminAPI.InstanceController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
|
|
|
import Pleroma.Web.ControllerHelper, only: [fetch_integer_param: 3]
|
|
|
|
|
2021-07-17 13:55:05 -06:00
|
|
|
alias Pleroma.Instances.Instance
|
2021-07-17 12:05:25 -06:00
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
|
|
alias Pleroma.Web.AdminAPI
|
|
|
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
|
|
|
|
|
|
|
require Logger
|
|
|
|
|
|
|
|
@default_page_size 50
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["admin:read:statuses"]}
|
2021-07-17 14:00:15 -06:00
|
|
|
when action in [:list_statuses]
|
2021-07-17 12:05:25 -06:00
|
|
|
)
|
|
|
|
|
2021-07-17 13:55:05 -06:00
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["admin:write:accounts", "admin:write:statuses"]}
|
2021-07-17 14:00:15 -06:00
|
|
|
when action in [:delete]
|
2021-07-17 13:55:05 -06:00
|
|
|
)
|
|
|
|
|
2021-07-17 12:05:25 -06:00
|
|
|
action_fallback(AdminAPI.FallbackController)
|
|
|
|
|
2021-07-17 14:00:15 -06:00
|
|
|
def list_statuses(conn, %{"instance" => instance} = params) do
|
2021-07-17 12:05:25 -06:00
|
|
|
with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true
|
|
|
|
{page, page_size} = page_params(params)
|
|
|
|
|
|
|
|
result =
|
|
|
|
ActivityPub.fetch_statuses(nil, %{
|
|
|
|
instance: instance,
|
|
|
|
limit: page_size,
|
|
|
|
offset: (page - 1) * page_size,
|
|
|
|
exclude_reblogs: not with_reblogs,
|
|
|
|
total: true
|
|
|
|
})
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_view(AdminAPI.StatusView)
|
|
|
|
|> render("index.json", %{total: result[:total], activities: result[:items], as: :activity})
|
|
|
|
end
|
|
|
|
|
2021-07-17 14:00:15 -06:00
|
|
|
def delete(conn, %{"instance" => instance}) do
|
2021-07-17 13:55:05 -06:00
|
|
|
with {:ok, _job} <- Instance.delete_users_and_activities(instance) do
|
|
|
|
json(conn, instance)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-17 12:05:25 -06:00
|
|
|
defp page_params(params) do
|
|
|
|
{
|
|
|
|
fetch_integer_param(params, "page", 1),
|
|
|
|
fetch_integer_param(params, "page_size", @default_page_size)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|