1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 import Pleroma.Web.ApiSpec.Helpers
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
17 def remote_operation do
19 tags: ["Emoji Packs"],
20 summary: "Make request to another instance for emoji packs list",
21 security: [%{"oAuth" => ["write"]}],
22 parameters: [url_param()],
23 operationId: "PleromaAPI.EmojiPackController.remote",
25 200 => emoji_packs_response(),
26 500 => Operation.response("Error", "application/json", ApiError)
31 def index_operation do
33 tags: ["Emoji Packs"],
34 summary: "Lists local custom emoji packs",
35 operationId: "PleromaAPI.EmojiPackController.index",
40 %Schema{type: :integer, default: 1},
46 %Schema{type: :integer, default: 50},
47 "Number of statuses to return"
51 200 => emoji_packs_response()
58 tags: ["Emoji Packs"],
59 summary: "Show emoji pack",
60 operationId: "PleromaAPI.EmojiPackController.show",
61 parameters: [name_param()],
63 200 => Operation.response("Emoji Pack", "application/json", emoji_pack()),
64 400 => Operation.response("Bad Request", "application/json", ApiError),
65 404 => Operation.response("Not Found", "application/json", ApiError)
70 def archive_operation do
72 tags: ["Emoji Packs"],
73 summary: "Requests a local pack archive from the instance",
74 operationId: "PleromaAPI.EmojiPackController.archive",
75 parameters: [name_param()],
78 Operation.response("Archive file", "application/octet-stream", %Schema{
82 403 => Operation.response("Forbidden", "application/json", ApiError),
83 404 => Operation.response("Not Found", "application/json", ApiError)
88 def download_operation do
90 tags: ["Emoji Packs"],
91 summary: "Download pack from another instance",
92 operationId: "PleromaAPI.EmojiPackController.download",
93 security: [%{"oAuth" => ["write"]}],
94 requestBody: request_body("Parameters", download_request(), required: true),
97 500 => Operation.response("Error", "application/json", ApiError)
102 defp download_request do
105 required: [:url, :name],
110 description: "URL of the instance to download from"
112 name: %Schema{type: :string, format: :uri, description: "Pack Name"},
113 as: %Schema{type: :string, format: :uri, description: "Save as"}
118 def create_operation do
120 tags: ["Emoji Packs"],
121 summary: "Create an empty pack",
122 operationId: "PleromaAPI.EmojiPackController.create",
123 security: [%{"oAuth" => ["write"]}],
124 parameters: [name_param()],
126 200 => ok_response(),
127 400 => Operation.response("Not Found", "application/json", ApiError),
128 409 => Operation.response("Conflict", "application/json", ApiError),
129 500 => Operation.response("Error", "application/json", ApiError)
134 def delete_operation do
136 tags: ["Emoji Packs"],
137 summary: "Delete a custom emoji pack",
138 operationId: "PleromaAPI.EmojiPackController.delete",
139 security: [%{"oAuth" => ["write"]}],
140 parameters: [name_param()],
142 200 => ok_response(),
143 400 => Operation.response("Bad Request", "application/json", ApiError),
144 404 => Operation.response("Not Found", "application/json", ApiError)
149 def update_operation do
151 tags: ["Emoji Packs"],
152 summary: "Updates (replaces) pack metadata",
153 operationId: "PleromaAPI.EmojiPackController.update",
154 security: [%{"oAuth" => ["write"]}],
155 requestBody: request_body("Parameters", update_request(), required: true),
156 parameters: [name_param()],
158 200 => Operation.response("Metadata", "application/json", metadata()),
159 400 => Operation.response("Bad Request", "application/json", ApiError)
164 def add_file_operation do
166 tags: ["Emoji Packs"],
167 summary: "Add new file to the pack",
168 operationId: "PleromaAPI.EmojiPackController.add_file",
169 security: [%{"oAuth" => ["write"]}],
170 requestBody: request_body("Parameters", add_file_request(), required: true),
171 parameters: [name_param()],
173 200 => Operation.response("Files Object", "application/json", files_object()),
174 400 => Operation.response("Bad Request", "application/json", ApiError),
175 409 => Operation.response("Conflict", "application/json", ApiError)
180 defp add_file_request do
187 "File needs to be uploaded with the multipart request or link to remote file",
189 %Schema{type: :string, format: :binary},
190 %Schema{type: :string, format: :uri}
196 "Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
201 "New emoji file name. If not specified will be taken from original filename."
207 def update_file_operation do
209 tags: ["Emoji Packs"],
210 summary: "Add new file to the pack",
211 operationId: "PleromaAPI.EmojiPackController.update_file",
212 security: [%{"oAuth" => ["write"]}],
213 requestBody: request_body("Parameters", update_file_request(), required: true),
214 parameters: [name_param()],
216 200 => Operation.response("Files Object", "application/json", files_object()),
217 400 => Operation.response("Bad Request", "application/json", ApiError),
218 409 => Operation.response("Conflict", "application/json", ApiError)
223 defp update_file_request do
226 required: [:shortcode, :new_shortcode, :new_filename],
230 description: "Emoji file shortcode"
232 new_shortcode: %Schema{
234 description: "New emoji file shortcode"
236 new_filename: %Schema{
238 description: "New filename for emoji file"
242 description: "With true value to overwrite existing emoji with new shortcode",
249 def delete_file_operation do
251 tags: ["Emoji Packs"],
252 summary: "Delete emoji file from pack",
253 operationId: "PleromaAPI.EmojiPackController.delete_file",
254 security: [%{"oAuth" => ["write"]}],
257 Operation.parameter(:shortcode, :query, :string, "File shortcode",
263 200 => Operation.response("Files Object", "application/json", files_object()),
264 400 => Operation.response("Bad Request", "application/json", ApiError)
269 def import_from_filesystem_operation do
271 tags: ["Emoji Packs"],
272 summary: "Imports packs from filesystem",
273 operationId: "PleromaAPI.EmojiPackController.import",
274 security: [%{"oAuth" => ["write"]}],
277 Operation.response("Array of imported pack names", "application/json", %Schema{
279 items: %Schema{type: :string}
286 Operation.parameter(:name, :path, :string, "Pack Name", example: "cofe", required: true)
293 %Schema{type: :string, format: :uri},
294 "URL of the instance",
300 Operation.response("Ok", "application/json", %Schema{type: :string, example: "ok"})
303 defp emoji_packs_response do
305 "Object with pack names as keys and pack contents as values",
309 additionalProperties: emoji_pack(),
311 "emojos" => emoji_pack().example
322 files: files_object(),
326 license: %Schema{type: :string},
327 homepage: %Schema{type: :string, format: :uri},
328 description: %Schema{type: :string},
329 "can-download": %Schema{type: :boolean},
330 "share-files": %Schema{type: :boolean},
331 "download-sha256": %Schema{type: :string}
336 "files" => %{"emacs" => "emacs.png", "guix" => "guix.png"},
338 "license" => "Test license",
339 "homepage" => "https://pleroma.social",
340 "description" => "Test description",
341 "can-download" => true,
342 "share-files" => true,
343 "download-sha256" => "57482F30674FD3DE821FF48C81C00DA4D4AF1F300209253684ABA7075E5FC238"
352 additionalProperties: %Schema{type: :string},
353 description: "Object with emoji names as keys and filenames as values"
357 defp update_request do
363 description: "Metadata to replace the old one",
365 license: %Schema{type: :string},
366 homepage: %Schema{type: :string, format: :uri},
367 description: %Schema{type: :string},
368 "fallback-src": %Schema{
371 description: "Fallback url to download pack from"
373 "fallback-src-sha256": %Schema{
375 description: "SHA256 encoded for fallback pack archive"
377 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}
388 license: %Schema{type: :string},
389 homepage: %Schema{type: :string, format: :uri},
390 description: %Schema{type: :string},
391 "fallback-src": %Schema{
394 description: "Fallback url to download pack from"
396 "fallback-src-sha256": %Schema{
398 description: "SHA256 encoded for fallback pack archive"
400 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}