Return the file content for GET /api/pleroma/admin/instance_document/:document_name
This commit is contained in:
parent
582ad5d4e1
commit
c711a2b157
5 changed files with 26 additions and 21 deletions
|
|
@ -5,6 +5,7 @@
|
|||
defmodule Pleroma.Web.AdminAPI.InstanceDocumentController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
alias Pleroma.Plugs.InstanceStatic
|
||||
alias Pleroma.Plugs.OAuthScopesPlug
|
||||
alias Pleroma.Web.InstanceDocument
|
||||
|
||||
|
|
@ -18,8 +19,11 @@ defmodule Pleroma.Web.AdminAPI.InstanceDocumentController do
|
|||
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) do
|
||||
json(conn, %{"url" => url})
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.InstanceDocumentOperation do
|
|||
| Helpers.admin_api_params()
|
||||
],
|
||||
responses: %{
|
||||
200 => Operation.response("InstanceDocument", "application/json", instance_document()),
|
||||
200 => document_content(),
|
||||
400 => Operation.response("Bad Request", "application/json", ApiError),
|
||||
403 => Operation.response("Forbidden", "application/json", ApiError),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
|
|
@ -105,4 +105,11 @@ defmodule Pleroma.Web.ApiSpec.Admin.InstanceDocumentOperation do
|
|||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp document_content do
|
||||
Operation.response("InstanceDocumentContent", "text/html", %Schema{
|
||||
type: :string,
|
||||
example: "<h1>Instance panel</h1>"
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ defmodule Pleroma.Web.InstanceDocument do
|
|||
@spec get(String.t()) :: {:ok, String.t()} | {:error, atom()}
|
||||
def get(document_name) do
|
||||
case Map.fetch(@instance_documents, document_name) do
|
||||
{:ok, path} -> {:ok, Path.join(Endpoint.url(), path)}
|
||||
{:ok, path} -> {:ok, path}
|
||||
_ -> {:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue