diff options
author | Roman Chvanikov <chvanikoff@pm.me> | 2020-09-20 19:27:27 +0300 |
---|---|---|
committer | Roman Chvanikov <chvanikoff@pm.me> | 2020-09-20 19:27:27 +0300 |
commit | 4987ee6256c4227793240c74043845a661e3d37b (patch) | |
tree | 40abf0e0c85df9788b59f24ed4026ae00a89e5e5 /lib/pleroma/web/admin_api/controllers/instance_document_controller.ex | |
parent | 44e8b6037ae71881327451dcf7d9351f1ba82674 (diff) | |
parent | 882c1fc6bdff4e27955730a412d73ead0e67a741 (diff) | |
download | pleroma-4987ee6256c4227793240c74043845a661e3d37b.tar.gz |
Merge branch 'develop' into feature/expire-mutes
Diffstat (limited to 'lib/pleroma/web/admin_api/controllers/instance_document_controller.ex')
-rw-r--r-- | lib/pleroma/web/admin_api/controllers/instance_document_controller.ex | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/pleroma/web/admin_api/controllers/instance_document_controller.ex b/lib/pleroma/web/admin_api/controllers/instance_document_controller.ex new file mode 100644 index 000000000..504d9b517 --- /dev/null +++ b/lib/pleroma/web/admin_api/controllers/instance_document_controller.ex @@ -0,0 +1,41 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.AdminAPI.InstanceDocumentController do + use Pleroma.Web, :controller + + alias Pleroma.Plugs.InstanceStatic + alias Pleroma.Plugs.OAuthScopesPlug + alias Pleroma.Web.InstanceDocument + + plug(Pleroma.Web.ApiSpec.CastAndValidate) + + action_fallback(Pleroma.Web.AdminAPI.FallbackController) + + defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.InstanceDocumentOperation + + plug(OAuthScopesPlug, %{scopes: ["read"], admin: true} when action == :show) + plug(OAuthScopesPlug, %{scopes: ["write"], admin: true} when action in [:update, :delete]) + + def show(conn, %{name: document_name}) do + with {:ok, url} <- InstanceDocument.get(document_name), + {:ok, content} <- File.read(InstanceStatic.file_path(url)) do + conn + |> put_resp_content_type("text/html") + |> send_resp(200, content) + end + end + + def update(%{body_params: %{file: file}} = conn, %{name: document_name}) do + with {:ok, url} <- InstanceDocument.put(document_name, file.path) do + json(conn, %{"url" => url}) + end + end + + def delete(conn, %{name: document_name}) do + with :ok <- InstanceDocument.delete(document_name) do + json(conn, %{}) + end + end +end |