add remote user count for the heck of it
[akkoma] / lib / pleroma / web / api_spec / operations / media_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.MediaOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Helpers
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 alias Pleroma.Web.ApiSpec.Schemas.Attachment
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 create_operation do
18 %Operation{
19 tags: ["Media attachments"],
20 summary: "Upload media as attachment",
21 description: "Creates an attachment to be used with a new status.",
22 operationId: "MediaController.create",
23 security: [%{"oAuth" => ["write:media"]}],
24 requestBody: Helpers.request_body("Parameters", create_request()),
25 responses: %{
26 200 => Operation.response("Media", "application/json", Attachment),
27 400 => Operation.response("Media", "application/json", ApiError),
28 401 => Operation.response("Media", "application/json", ApiError),
29 422 => Operation.response("Media", "application/json", ApiError)
30 }
31 }
32 end
33
34 defp create_request do
35 %Schema{
36 title: "MediaCreateRequest",
37 description: "POST body for creating an attachment",
38 type: :object,
39 required: [:file],
40 properties: %{
41 file: %Schema{
42 type: :string,
43 format: :binary,
44 description: "The file to be attached, using multipart form data."
45 },
46 description: %Schema{
47 type: :string,
48 description: "A plain-text description of the media, for accessibility purposes."
49 },
50 focus: %Schema{
51 type: :string,
52 description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
53 }
54 }
55 }
56 end
57
58 def update_operation do
59 %Operation{
60 tags: ["Media attachments"],
61 summary: "Update attachment",
62 description: "Creates an attachment to be used with a new status.",
63 operationId: "MediaController.update",
64 security: [%{"oAuth" => ["write:media"]}],
65 parameters: [id_param()],
66 requestBody: Helpers.request_body("Parameters", update_request()),
67 responses: %{
68 200 => Operation.response("Media", "application/json", Attachment),
69 400 => Operation.response("Media", "application/json", ApiError),
70 401 => Operation.response("Media", "application/json", ApiError),
71 422 => Operation.response("Media", "application/json", ApiError)
72 }
73 }
74 end
75
76 defp update_request do
77 %Schema{
78 title: "MediaUpdateRequest",
79 description: "POST body for updating an attachment",
80 type: :object,
81 properties: %{
82 file: %Schema{
83 type: :string,
84 format: :binary,
85 description: "The file to be attached, using multipart form data."
86 },
87 description: %Schema{
88 type: :string,
89 description: "A plain-text description of the media, for accessibility purposes."
90 },
91 focus: %Schema{
92 type: :string,
93 description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
94 }
95 }
96 }
97 end
98
99 def show_operation do
100 %Operation{
101 tags: ["Media attachments"],
102 summary: "Attachment",
103 operationId: "MediaController.show",
104 parameters: [id_param()],
105 security: [%{"oAuth" => ["read:media"]}],
106 responses: %{
107 200 => Operation.response("Media", "application/json", Attachment),
108 401 => Operation.response("Media", "application/json", ApiError),
109 403 => Operation.response("Media", "application/json", ApiError),
110 422 => Operation.response("Media", "application/json", ApiError)
111 }
112 }
113 end
114
115 def create2_operation do
116 %Operation{
117 tags: ["Media attachments"],
118 summary: "Upload media as attachment (v2)",
119 description: "Creates an attachment to be used with a new status.",
120 operationId: "MediaController.create2",
121 security: [%{"oAuth" => ["write:media"]}],
122 requestBody: Helpers.request_body("Parameters", create_request()),
123 responses: %{
124 202 => Operation.response("Media", "application/json", Attachment),
125 400 => Operation.response("Media", "application/json", ApiError),
126 422 => Operation.response("Media", "application/json", ApiError),
127 500 => Operation.response("Media", "application/json", ApiError)
128 }
129 }
130 end
131
132 defp id_param do
133 Operation.parameter(:id, :path, :string, "The ID of the Attachment entity")
134 end
135 end