1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.BackupController do
6 use Pleroma.Web, :controller
8 alias Pleroma.User.Backup
9 alias Pleroma.Web.Plugs.OAuthScopesPlug
11 action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
12 plug(OAuthScopesPlug, %{scopes: ["read:accounts"]} when action in [:index, :create])
13 plug(OpenApiSpex.Plug.CastAndValidate, render_error: Pleroma.Web.ApiSpec.RenderError)
15 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaBackupOperation
17 def index(%{assigns: %{user: user}} = conn, _params) do
18 backups = Backup.list(user)
19 render(conn, "index.json", backups: backups)
22 def create(%{assigns: %{user: user}} = conn, _params) do
23 with {:ok, _} <- Backup.create(user) do
24 backups = Backup.list(user)
25 render(conn, "index.json", backups: backups)