logo

pleroma

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

frontend_operation.ex (2521B)


  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.Admin.FrontendOperation 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 index_operation do
  14. %Operation{
  15. tags: ["Frontend management"],
  16. summary: "Retrieve a list of available frontends",
  17. operationId: "AdminAPI.FrontendController.index",
  18. security: [%{"oAuth" => ["admin:read"]}],
  19. responses: %{
  20. 200 => Operation.response("Response", "application/json", list_of_frontends()),
  21. 403 => Operation.response("Forbidden", "application/json", ApiError)
  22. }
  23. }
  24. end
  25. def install_operation do
  26. %Operation{
  27. tags: ["Frontend management"],
  28. summary: "Install a frontend",
  29. operationId: "AdminAPI.FrontendController.install",
  30. security: [%{"oAuth" => ["admin:read"]}],
  31. requestBody: request_body("Parameters", install_request(), required: true),
  32. responses: %{
  33. 200 => Operation.response("Response", "application/json", list_of_frontends()),
  34. 403 => Operation.response("Forbidden", "application/json", ApiError),
  35. 400 => Operation.response("Error", "application/json", ApiError)
  36. }
  37. }
  38. end
  39. defp list_of_frontends do
  40. %Schema{
  41. type: :array,
  42. items: %Schema{
  43. type: :object,
  44. properties: %{
  45. name: %Schema{type: :string},
  46. git: %Schema{type: :string, format: :uri, nullable: true},
  47. build_url: %Schema{type: :string, format: :uri, nullable: true},
  48. ref: %Schema{type: :string, nullable: true},
  49. installed: %Schema{type: :boolean},
  50. installed_refs: %Schema{type: :array, items: %Schema{type: :string}}
  51. }
  52. }
  53. }
  54. end
  55. defp install_request do
  56. %Schema{
  57. title: "FrontendInstallRequest",
  58. type: :object,
  59. required: [:name],
  60. properties: %{
  61. name: %Schema{
  62. type: :string
  63. },
  64. ref: %Schema{
  65. type: :string
  66. },
  67. file: %Schema{
  68. type: :string
  69. },
  70. build_url: %Schema{
  71. type: :string
  72. },
  73. build_dir: %Schema{
  74. type: :string
  75. }
  76. }
  77. }
  78. end
  79. end