1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.FrontendController do
6 use Pleroma.Web, :controller
9 alias Pleroma.Web.Plugs.OAuthScopesPlug
11 plug(Pleroma.Web.ApiSpec.CastAndValidate)
12 plug(OAuthScopesPlug, %{scopes: ["admin:write"]} when action == :install)
13 plug(OAuthScopesPlug, %{scopes: ["admin:read"]} when action == :index)
14 action_fallback(Pleroma.Web.AdminAPI.FallbackController)
16 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.FrontendOperation
18 def index(conn, _params) do
19 installed = installed()
22 [:frontends, :available]
24 |> Enum.map(fn {name, desc} ->
25 Map.put(desc, "installed", name in installed)
28 render(conn, "index.json", frontends: frontends)
31 def install(%{body_params: params} = conn, _params) do
32 with :ok <- Pleroma.Frontend.install(params.name, Map.delete(params, :name)) do
38 frontend_directory = Pleroma.Frontend.dir()
40 if File.exists?(frontend_directory) do
41 File.ls!(frontend_directory)