logo

pleroma

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

media_operation.ex (4708B)


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