logo

pleroma

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

pleroma_backup_operation.ex (2678B)


  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.PleromaBackupOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  8. def open_api_operation(action) do
  9. operation = String.to_existing_atom("#{action}_operation")
  10. apply(__MODULE__, operation, [])
  11. end
  12. def index_operation do
  13. %Operation{
  14. tags: ["Backups"],
  15. summary: "List backups",
  16. security: [%{"oAuth" => ["read:backups"]}],
  17. operationId: "PleromaAPI.BackupController.index",
  18. responses: %{
  19. 200 =>
  20. Operation.response(
  21. "An array of backups",
  22. "application/json",
  23. %Schema{
  24. type: :array,
  25. items: backup()
  26. }
  27. ),
  28. 400 => Operation.response("Bad Request", "application/json", ApiError)
  29. }
  30. }
  31. end
  32. def create_operation do
  33. %Operation{
  34. tags: ["Backups"],
  35. summary: "Create a backup",
  36. security: [%{"oAuth" => ["read:backups"]}],
  37. operationId: "PleromaAPI.BackupController.create",
  38. responses: %{
  39. 200 =>
  40. Operation.response(
  41. "An array of backups",
  42. "application/json",
  43. %Schema{
  44. type: :array,
  45. items: backup()
  46. }
  47. ),
  48. 400 => Operation.response("Bad Request", "application/json", ApiError)
  49. }
  50. }
  51. end
  52. defp backup do
  53. %Schema{
  54. title: "Backup",
  55. description: "Response schema for a backup",
  56. type: :object,
  57. properties: %{
  58. inserted_at: %Schema{type: :string, format: :"date-time"},
  59. content_type: %Schema{type: :string},
  60. file_name: %Schema{type: :string},
  61. file_size: %Schema{type: :integer},
  62. processed: %Schema{type: :boolean, description: "whether this backup has succeeded"},
  63. state: %Schema{
  64. type: :string,
  65. description: "the state of the backup",
  66. enum: ["pending", "running", "complete", "failed"]
  67. },
  68. processed_number: %Schema{type: :integer, description: "the number of records processed"}
  69. },
  70. example: %{
  71. "content_type" => "application/zip",
  72. "file_name" =>
  73. "https://cofe.fe:4000/media/backups/archive-foobar-20200908T164207-Yr7vuT5Wycv-sN3kSN2iJ0k-9pMo60j9qmvRCdDqIew.zip",
  74. "file_size" => 4105,
  75. "inserted_at" => "2020-09-08T16:42:07.000Z",
  76. "processed" => true,
  77. "state" => "complete",
  78. "processed_number" => 20
  79. }
  80. }
  81. end
  82. end