FrontendController: Return error on installation error.

This commit is contained in:
lain 2020-11-17 16:43:07 +01:00
parent f69fe36ebf
commit bb9650f3c2
4 changed files with 26 additions and 4 deletions

View File

@ -42,9 +42,11 @@ defmodule Pleroma.Frontend do
else else
{:download_or_unzip, _} -> {:download_or_unzip, _} ->
Logger.info("Could not download or unzip the frontend") Logger.info("Could not download or unzip the frontend")
{:error, "Could not download or unzip the frontend"}
_e -> _e ->
Logger.info("Could not install the frontend") Logger.info("Could not install the frontend")
{:error, "Could not install the frontend"}
end end
end end

View File

@ -29,10 +29,10 @@ defmodule Pleroma.Web.AdminAPI.FrontendController do
end end
def install(%{body_params: params} = conn, _params) do def install(%{body_params: params} = conn, _params) do
Pleroma.Frontend.install(params.name, Map.delete(params, :name)) with :ok <- Pleroma.Frontend.install(params.name, Map.delete(params, :name)) do
index(conn, %{}) index(conn, %{})
end end
end
defp installed do defp installed do
File.ls!(Pleroma.Frontend.dir()) File.ls!(Pleroma.Frontend.dir())

View File

@ -36,7 +36,8 @@ defmodule Pleroma.Web.ApiSpec.Admin.FrontendOperation do
requestBody: request_body("Parameters", install_request(), required: true), requestBody: request_body("Parameters", install_request(), required: true),
responses: %{ responses: %{
200 => Operation.response("Response", "application/json", list_of_frontends()), 200 => Operation.response("Response", "application/json", list_of_frontends()),
403 => Operation.response("Forbidden", "application/json", ApiError) 403 => Operation.response("Forbidden", "application/json", ApiError),
400 => Operation.response("Error", "application/json", ApiError)
} }
} }
end end

View File

@ -118,5 +118,24 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"])) assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
end end
test "failing returns an error", %{conn: conn} do
Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
%Tesla.Env{status: 404, body: ""}
end)
result =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/frontends/install", %{
name: "unknown",
ref: "baka",
build_url: "http://gensokyo.2hu/madeup.zip",
build_dir: ""
})
|> json_response_and_validate_schema(400)
assert result == %{"error" => "Could not download or unzip the frontend"}
end
end end
end end