logo

pleroma

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

backup_view.ex (1108B)


  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.PleromaAPI.BackupView do
  5. use Pleroma.Web, :view
  6. alias Pleroma.User.Backup
  7. alias Pleroma.Web.CommonAPI.Utils
  8. def render("show.json", %{backup: %Backup{} = backup}) do
  9. # To deal with records before the migration
  10. state =
  11. if backup.state == :invalid do
  12. if backup.processed, do: :complete, else: :failed
  13. else
  14. backup.state
  15. end
  16. %{
  17. id: backup.id,
  18. content_type: backup.content_type,
  19. url: download_url(backup),
  20. file_size: backup.file_size,
  21. processed: backup.processed,
  22. state: to_string(state),
  23. processed_number: backup.processed_number,
  24. inserted_at: Utils.to_masto_date(backup.inserted_at)
  25. }
  26. end
  27. def render("index.json", %{backups: backups}) do
  28. render_many(backups, __MODULE__, "show.json")
  29. end
  30. def download_url(%Backup{file_name: file_name}) do
  31. Pleroma.Upload.base_url() <> "/backups/" <> file_name
  32. end
  33. end