[#1940] Added `admin_token` param (as `admin_api_params/0`) to existing Admin API...
[akkoma] / lib / pleroma / web / api_spec / operations / admin / media_proxy_cache_operation.ex
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
5 defmodule Pleroma.Web.ApiSpec.Admin.MediaProxyCacheOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
9
10 import Pleroma.Web.ApiSpec.Helpers
11
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
15 end
16
17 def index_operation do
18 %Operation{
19 tags: ["Admin", "MediaProxyCache"],
20 summary: "Fetch a paginated list of all banned MediaProxy URLs in Cachex",
21 operationId: "AdminAPI.MediaProxyCacheController.index",
22 security: [%{"oAuth" => ["read:media_proxy_caches"]}],
23 parameters: [
24 Operation.parameter(
25 :page,
26 :query,
27 %Schema{type: :integer, default: 1},
28 "Page"
29 ),
30 Operation.parameter(
31 :page_size,
32 :query,
33 %Schema{type: :integer, default: 50},
34 "Number of statuses to return"
35 )
36 | admin_api_params()
37 ],
38 responses: %{
39 200 => success_response()
40 }
41 }
42 end
43
44 def delete_operation do
45 %Operation{
46 tags: ["Admin", "MediaProxyCache"],
47 summary: "Remove a banned MediaProxy URL from Cachex",
48 operationId: "AdminAPI.MediaProxyCacheController.delete",
49 security: [%{"oAuth" => ["write:media_proxy_caches"]}],
50 parameters: admin_api_params(),
51 requestBody:
52 request_body(
53 "Parameters",
54 %Schema{
55 type: :object,
56 required: [:urls],
57 properties: %{
58 urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}}
59 }
60 },
61 required: true
62 ),
63 responses: %{
64 200 => success_response(),
65 400 => Operation.response("Error", "application/json", ApiError)
66 }
67 }
68 end
69
70 def purge_operation do
71 %Operation{
72 tags: ["Admin", "MediaProxyCache"],
73 summary: "Purge and optionally ban a MediaProxy URL",
74 operationId: "AdminAPI.MediaProxyCacheController.purge",
75 security: [%{"oAuth" => ["write:media_proxy_caches"]}],
76 parameters: admin_api_params(),
77 requestBody:
78 request_body(
79 "Parameters",
80 %Schema{
81 type: :object,
82 required: [:urls],
83 properties: %{
84 urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}},
85 ban: %Schema{type: :boolean, default: true}
86 }
87 },
88 required: true
89 ),
90 responses: %{
91 200 => success_response(),
92 400 => Operation.response("Error", "application/json", ApiError)
93 }
94 }
95 end
96
97 defp success_response do
98 Operation.response("Array of banned MediaProxy URLs in Cachex", "application/json", %Schema{
99 type: :object,
100 properties: %{
101 urls: %Schema{
102 type: :array,
103 items: %Schema{
104 type: :string,
105 format: :uri,
106 description: "MediaProxy URLs"
107 }
108 }
109 }
110 })
111 end
112 end