logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

pleroma_emoji_file_operation.ex (4934B)


  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. defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  8. import Pleroma.Web.ApiSpec.Helpers
  9. def open_api_operation(action) do
  10. operation = String.to_existing_atom("#{action}_operation")
  11. apply(__MODULE__, operation, [])
  12. end
  13. def create_operation do
  14. %Operation{
  15. tags: ["Emoji pack administration"],
  16. summary: "Add new file to the pack",
  17. operationId: "PleromaAPI.EmojiPackController.add_file",
  18. security: [%{"oAuth" => ["admin:write"]}],
  19. requestBody: request_body("Parameters", create_request(), required: true),
  20. parameters: [name_param()],
  21. responses: %{
  22. 200 => Operation.response("Files Object", "application/json", files_object()),
  23. 422 => Operation.response("Unprocessable Entity", "application/json", ApiError),
  24. 404 => Operation.response("Not Found", "application/json", ApiError),
  25. 400 => Operation.response("Bad Request", "application/json", ApiError),
  26. 409 => Operation.response("Conflict", "application/json", ApiError),
  27. 500 => Operation.response("Error", "application/json", ApiError)
  28. }
  29. }
  30. end
  31. defp create_request do
  32. %Schema{
  33. type: :object,
  34. required: [:file],
  35. properties: %{
  36. file: %Schema{
  37. description:
  38. "File needs to be uploaded with the multipart request or link to remote file",
  39. anyOf: [
  40. %Schema{type: :string, format: :binary},
  41. %Schema{type: :string, format: :uri}
  42. ]
  43. },
  44. shortcode: %Schema{
  45. type: :string,
  46. description:
  47. "Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
  48. },
  49. filename: %Schema{
  50. type: :string,
  51. description:
  52. "New emoji file name. If not specified will be taken from original filename."
  53. }
  54. }
  55. }
  56. end
  57. def update_operation do
  58. %Operation{
  59. tags: ["Emoji pack administration"],
  60. summary: "Add new file to the pack",
  61. operationId: "PleromaAPI.EmojiPackController.update_file",
  62. security: [%{"oAuth" => ["admin:write"]}],
  63. requestBody: request_body("Parameters", update_request(), required: true),
  64. parameters: [name_param()],
  65. responses: %{
  66. 200 => Operation.response("Files Object", "application/json", files_object()),
  67. 404 => Operation.response("Not Found", "application/json", ApiError),
  68. 400 => Operation.response("Bad Request", "application/json", ApiError),
  69. 409 => Operation.response("Conflict", "application/json", ApiError),
  70. 422 => Operation.response("Unprocessable Entity", "application/json", ApiError)
  71. }
  72. }
  73. end
  74. defp update_request do
  75. %Schema{
  76. type: :object,
  77. required: [:shortcode, :new_shortcode, :new_filename],
  78. properties: %{
  79. shortcode: %Schema{
  80. type: :string,
  81. description: "Emoji file shortcode"
  82. },
  83. new_shortcode: %Schema{
  84. type: :string,
  85. description: "New emoji file shortcode"
  86. },
  87. new_filename: %Schema{
  88. type: :string,
  89. description: "New filename for emoji file"
  90. },
  91. force: %Schema{
  92. type: :boolean,
  93. description: "With true value to overwrite existing emoji with new shortcode",
  94. default: false
  95. }
  96. }
  97. }
  98. end
  99. def delete_operation do
  100. %Operation{
  101. tags: ["Emoji pack administration"],
  102. summary: "Delete emoji file from pack",
  103. operationId: "PleromaAPI.EmojiPackController.delete_file",
  104. security: [%{"oAuth" => ["admin:write"]}],
  105. parameters: [
  106. name_param(),
  107. Operation.parameter(:shortcode, :query, :string, "File shortcode",
  108. example: "cofe",
  109. required: true
  110. )
  111. ],
  112. responses: %{
  113. 200 => Operation.response("Files Object", "application/json", files_object()),
  114. 400 => Operation.response("Bad Request", "application/json", ApiError),
  115. 404 => Operation.response("Not Found", "application/json", ApiError),
  116. 422 => Operation.response("Unprocessable Entity", "application/json", ApiError)
  117. }
  118. }
  119. end
  120. defp name_param do
  121. Operation.parameter(:name, :query, :string, "Pack Name", example: "cofe", required: true)
  122. end
  123. defp files_object do
  124. %Schema{
  125. type: :object,
  126. additionalProperties: %Schema{
  127. type: :string,
  128. description: "Filename of the emoji",
  129. extensions: %{"x-additionalPropertiesName": "Emoji name"}
  130. },
  131. description: "Object with emoji names as keys and filenames as values"
  132. }
  133. end
  134. end