Merge remote-tracking branch 'remotes/origin/develop' into 2168-media-preview-proxy
[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 ],
37 responses: %{
38 200 => success_response()
39 }
40 }
41 end
42
43 def delete_operation do
44 %Operation{
45 tags: ["Admin", "MediaProxyCache"],
46 summary: "Remove a banned MediaProxy URL from Cachex",
47 operationId: "AdminAPI.MediaProxyCacheController.delete",
48 security: [%{"oAuth" => ["write:media_proxy_caches"]}],
49 requestBody:
50 request_body(
51 "Parameters",
52 %Schema{
53 type: :object,
54 required: [:urls],
55 properties: %{
56 urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}}
57 }
58 },
59 required: true
60 ),
61 responses: %{
62 200 => success_response(),
63 400 => Operation.response("Error", "application/json", ApiError)
64 }
65 }
66 end
67
68 def purge_operation do
69 %Operation{
70 tags: ["Admin", "MediaProxyCache"],
71 summary: "Purge and optionally ban a MediaProxy URL",
72 operationId: "AdminAPI.MediaProxyCacheController.purge",
73 security: [%{"oAuth" => ["write:media_proxy_caches"]}],
74 requestBody:
75 request_body(
76 "Parameters",
77 %Schema{
78 type: :object,
79 required: [:urls],
80 properties: %{
81 urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}},
82 ban: %Schema{type: :boolean, default: true}
83 }
84 },
85 required: true
86 ),
87 responses: %{
88 200 => success_response(),
89 400 => Operation.response("Error", "application/json", ApiError)
90 }
91 }
92 end
93
94 defp success_response do
95 Operation.response("Array of banned MediaProxy URLs in Cachex", "application/json", %Schema{
96 type: :object,
97 properties: %{
98 urls: %Schema{
99 type: :array,
100 items: %Schema{
101 type: :string,
102 format: :uri,
103 description: "MediaProxy URLs"
104 }
105 }
106 }
107 })
108 end
109 end