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