move to 2.5.5
[anni] / lib / pleroma / web / api_spec / operations / admin / media_proxy_cache_operation.ex
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
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: ["MediaProxy cache"],
20       summary: "Retrieve a list of banned MediaProxy URLs",
21       operationId: "AdminAPI.MediaProxyCacheController.index",
22       security: [%{"oAuth" => ["admin:read:media_proxy_caches"]}],
23       parameters: [
24         Operation.parameter(
25           :query,
26           :query,
27           %Schema{type: :string, default: nil},
28           "Page"
29         ),
30         Operation.parameter(
31           :page,
32           :query,
33           %Schema{type: :integer, default: 1},
34           "Page"
35         ),
36         Operation.parameter(
37           :page_size,
38           :query,
39           %Schema{type: :integer, default: 50},
40           "Number of statuses to return"
41         )
42         | admin_api_params()
43       ],
44       responses: %{
45         200 =>
46           Operation.response(
47             "Array of MediaProxy URLs",
48             "application/json",
49             %Schema{
50               type: :object,
51               properties: %{
52                 count: %Schema{type: :integer},
53                 page_size: %Schema{type: :integer},
54                 urls: %Schema{
55                   type: :array,
56                   items: %Schema{
57                     type: :string,
58                     format: :uri,
59                     description: "MediaProxy URLs"
60                   }
61                 }
62               }
63             }
64           )
65       }
66     }
67   end
68
69   def delete_operation do
70     %Operation{
71       tags: ["MediaProxy cache"],
72       summary: "Remove a banned MediaProxy URL",
73       operationId: "AdminAPI.MediaProxyCacheController.delete",
74       security: [%{"oAuth" => ["admin:write:media_proxy_caches"]}],
75       parameters: admin_api_params(),
76       requestBody:
77         request_body(
78           "Parameters",
79           %Schema{
80             type: :object,
81             required: [:urls],
82             properties: %{
83               urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}}
84             }
85           },
86           required: true
87         ),
88       responses: %{
89         200 => empty_object_response(),
90         400 => Operation.response("Error", "application/json", ApiError)
91       }
92     }
93   end
94
95   def purge_operation do
96     %Operation{
97       tags: ["MediaProxy cache"],
98       summary: "Purge a URL from MediaProxy cache and optionally ban it",
99       operationId: "AdminAPI.MediaProxyCacheController.purge",
100       security: [%{"oAuth" => ["admin:write:media_proxy_caches"]}],
101       parameters: admin_api_params(),
102       requestBody:
103         request_body(
104           "Parameters",
105           %Schema{
106             type: :object,
107             required: [:urls],
108             properties: %{
109               urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}},
110               ban: %Schema{type: :boolean, default: true}
111             }
112           },
113           required: true
114         ),
115       responses: %{
116         200 => empty_object_response(),
117         400 => Operation.response("Error", "application/json", ApiError)
118       }
119     }
120   end
121 end