Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.5KB

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