2020-05-22 13:52:26 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-22 13:52:26 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ApiSpec.Admin.RelayOperation do
|
|
|
|
alias OpenApiSpex.Operation
|
|
|
|
alias OpenApiSpex.Schema
|
|
|
|
|
|
|
|
import Pleroma.Web.ApiSpec.Helpers
|
|
|
|
|
|
|
|
def open_api_operation(action) do
|
|
|
|
operation = String.to_existing_atom("#{action}_operation")
|
|
|
|
apply(__MODULE__, operation, [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_operation do
|
|
|
|
%Operation{
|
2021-02-03 12:38:59 +00:00
|
|
|
tags: ["Relays"],
|
|
|
|
summary: "Retrieve a list of relays",
|
2020-05-22 13:52:26 +00:00
|
|
|
operationId: "AdminAPI.RelayController.index",
|
2021-02-17 17:56:13 +00:00
|
|
|
security: [%{"oAuth" => ["admin:read"]}],
|
2020-07-14 16:31:05 +00:00
|
|
|
parameters: admin_api_params(),
|
2020-05-22 13:52:26 +00:00
|
|
|
responses: %{
|
|
|
|
200 =>
|
|
|
|
Operation.response("Response", "application/json", %Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
relays: %Schema{
|
|
|
|
type: :array,
|
2020-08-18 15:21:34 +00:00
|
|
|
items: relay()
|
2020-05-22 13:52:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def follow_operation do
|
|
|
|
%Operation{
|
2021-02-03 12:38:59 +00:00
|
|
|
tags: ["Relays"],
|
|
|
|
summary: "Follow a relay",
|
2020-05-22 13:52:26 +00:00
|
|
|
operationId: "AdminAPI.RelayController.follow",
|
2021-02-17 17:56:13 +00:00
|
|
|
security: [%{"oAuth" => ["admin:write:follows"]}],
|
2020-07-14 16:31:05 +00:00
|
|
|
parameters: admin_api_params(),
|
2020-08-18 15:21:34 +00:00
|
|
|
requestBody: request_body("Parameters", relay_url()),
|
2020-05-22 13:52:26 +00:00
|
|
|
responses: %{
|
2020-08-18 15:21:34 +00:00
|
|
|
200 => Operation.response("Status", "application/json", relay())
|
2020-05-22 13:52:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def unfollow_operation do
|
|
|
|
%Operation{
|
2021-02-03 12:38:59 +00:00
|
|
|
tags: ["Relays"],
|
|
|
|
summary: "Unfollow a relay",
|
2020-05-22 13:52:26 +00:00
|
|
|
operationId: "AdminAPI.RelayController.unfollow",
|
2021-02-17 17:56:13 +00:00
|
|
|
security: [%{"oAuth" => ["admin:write:follows"]}],
|
2020-07-14 16:31:05 +00:00
|
|
|
parameters: admin_api_params(),
|
2020-09-28 06:16:42 +00:00
|
|
|
requestBody: request_body("Parameters", relay_unfollow()),
|
2020-05-22 13:52:26 +00:00
|
|
|
responses: %{
|
|
|
|
200 =>
|
|
|
|
Operation.response("Status", "application/json", %Schema{
|
|
|
|
type: :string,
|
|
|
|
example: "http://mastodon.example.org/users/admin"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2020-08-18 15:21:34 +00:00
|
|
|
|
|
|
|
defp relay do
|
|
|
|
%Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
actor: %Schema{
|
|
|
|
type: :string,
|
|
|
|
example: "https://example.com/relay"
|
|
|
|
},
|
|
|
|
followed_back: %Schema{
|
|
|
|
type: :boolean,
|
|
|
|
description: "Is relay followed back by this actor?"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp relay_url do
|
|
|
|
%Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
relay_url: %Schema{type: :string, format: :uri}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2020-09-28 06:16:42 +00:00
|
|
|
|
|
|
|
defp relay_unfollow do
|
|
|
|
%Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
relay_url: %Schema{type: :string, format: :uri},
|
|
|
|
force: %Schema{type: :boolean, default: false}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2020-05-22 13:52:26 +00:00
|
|
|
end
|