forked from AkkomaGang/akkoma
Add support for install via file
and build_url
params
This commit is contained in:
parent
03e306785b
commit
d83c2bd330
4 changed files with 74 additions and 25 deletions
|
@ -8,16 +8,16 @@ defmodule Pleroma.Frontend do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def install(name, opts \\ []) do
|
def install(name, opts \\ []) do
|
||||||
cmd_frontend_info = %{
|
frontend_info = %{
|
||||||
"ref" => opts[:ref],
|
"ref" => opts[:ref],
|
||||||
"build_url" => opts[:build_url],
|
"build_url" => opts[:build_url],
|
||||||
"build_dir" => opts[:build_dir]
|
"build_dir" => opts[:build_dir]
|
||||||
}
|
}
|
||||||
|
|
||||||
config_frontend_info = Config.get([:frontends, :available, name], %{})
|
|
||||||
|
|
||||||
frontend_info =
|
frontend_info =
|
||||||
Map.merge(config_frontend_info, cmd_frontend_info, fn _key, config, cmd ->
|
[:frontends, :available, name]
|
||||||
|
|> Config.get(%{})
|
||||||
|
|> Map.merge(frontend_info, fn _key, config, cmd ->
|
||||||
# This only overrides things that are actually set
|
# This only overrides things that are actually set
|
||||||
cmd || config
|
cmd || config
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -49,7 +49,7 @@ defp list_of_frontends do
|
||||||
properties: %{
|
properties: %{
|
||||||
name: %Schema{type: :string},
|
name: %Schema{type: :string},
|
||||||
git: %Schema{type: :string, format: :uri, nullable: true},
|
git: %Schema{type: :string, format: :uri, nullable: true},
|
||||||
build_url: %Schema{type: :string, format: :uri},
|
build_url: %Schema{type: :string, format: :uri, nullable: true},
|
||||||
ref: %Schema{type: :string},
|
ref: %Schema{type: :string},
|
||||||
installed: %Schema{type: :boolean}
|
installed: %Schema{type: :boolean}
|
||||||
}
|
}
|
||||||
|
@ -64,12 +64,19 @@ defp install_request do
|
||||||
required: [:name],
|
required: [:name],
|
||||||
properties: %{
|
properties: %{
|
||||||
name: %Schema{
|
name: %Schema{
|
||||||
type: :string,
|
type: :string
|
||||||
nullable: false
|
|
||||||
},
|
},
|
||||||
ref: %Schema{
|
ref: %Schema{
|
||||||
type: :string,
|
type: :string
|
||||||
nullable: false
|
},
|
||||||
|
file: %Schema{
|
||||||
|
type: :string
|
||||||
|
},
|
||||||
|
build_url: %Schema{
|
||||||
|
type: :string
|
||||||
|
},
|
||||||
|
build_dir: %Schema{
|
||||||
|
type: :string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@ defmodule Pleroma.FrontendTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
alias Pleroma.Frontend
|
alias Pleroma.Frontend
|
||||||
|
|
||||||
import ExUnit.CaptureIO, only: [capture_io: 1]
|
|
||||||
|
|
||||||
@dir "test/frontend_static_test"
|
@dir "test/frontend_static_test"
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
|
@ -32,9 +30,7 @@ test "it downloads and unzips a known frontend" do
|
||||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
capture_io(fn ->
|
|
||||||
Frontend.install("pleroma")
|
Frontend.install("pleroma")
|
||||||
end)
|
|
||||||
|
|
||||||
assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
|
assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
|
||||||
end
|
end
|
||||||
|
@ -54,9 +50,7 @@ test "it also works given a file" do
|
||||||
File.write!(previously_existing, "yey")
|
File.write!(previously_existing, "yey")
|
||||||
assert File.exists?(previously_existing)
|
assert File.exists?(previously_existing)
|
||||||
|
|
||||||
capture_io(fn ->
|
|
||||||
Frontend.install("pleroma", file: "test/fixtures/tesla_mock/frontend.zip")
|
Frontend.install("pleroma", file: "test/fixtures/tesla_mock/frontend.zip")
|
||||||
end)
|
|
||||||
|
|
||||||
assert File.exists?(Path.join([folder, "test.txt"]))
|
assert File.exists?(Path.join([folder, "test.txt"]))
|
||||||
refute File.exists?(previously_existing)
|
refute File.exists?(previously_existing)
|
||||||
|
@ -67,13 +61,11 @@ test "it downloads and unzips unknown frontends" do
|
||||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
capture_io(fn ->
|
|
||||||
Frontend.install("unknown",
|
Frontend.install("unknown",
|
||||||
ref: "baka",
|
ref: "baka",
|
||||||
build_url: "http://gensokyo.2hu/madeup.zip",
|
build_url: "http://gensokyo.2hu/madeup.zip",
|
||||||
build_dir: ""
|
build_dir: ""
|
||||||
)
|
)
|
||||||
end)
|
|
||||||
|
|
||||||
assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
|
assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,7 +48,7 @@ test "it lists available frontends", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST /api/pleroma/admin/frontends" do
|
describe "POST /api/pleroma/admin/frontends" do
|
||||||
test "it installs a frontend", %{conn: conn} do
|
test "from available frontends", %{conn: conn} do
|
||||||
clear_config([:frontends, :available], %{
|
clear_config([:frontends, :available], %{
|
||||||
"pleroma" => %{
|
"pleroma" => %{
|
||||||
"ref" => "fantasy",
|
"ref" => "fantasy",
|
||||||
|
@ -90,5 +90,55 @@ test "it installs a frontend", %{conn: conn} do
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "from a file", %{conn: conn} do
|
||||||
|
clear_config([:frontends, :available], %{
|
||||||
|
"pleroma" => %{
|
||||||
|
"ref" => "fantasy",
|
||||||
|
"name" => "pleroma",
|
||||||
|
"build_dir" => ""
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/frontends", %{
|
||||||
|
name: "pleroma",
|
||||||
|
file: "test/fixtures/tesla_mock/frontend.zip"
|
||||||
|
})
|
||||||
|
|> json_response_and_validate_schema(:ok)
|
||||||
|
|
||||||
|
assert_enqueued(
|
||||||
|
worker: FrontendInstallerWorker,
|
||||||
|
args: %{
|
||||||
|
"name" => "pleroma",
|
||||||
|
"opts" => %{"file" => "test/fixtures/tesla_mock/frontend.zip"}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
ObanHelpers.perform(all_enqueued(worker: FrontendInstallerWorker))
|
||||||
|
|
||||||
|
assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "from an URL", %{conn: conn} do
|
||||||
|
Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
|
||||||
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
|
||||||
|
end)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/frontends", %{
|
||||||
|
name: "unknown",
|
||||||
|
ref: "baka",
|
||||||
|
build_url: "http://gensokyo.2hu/madeup.zip",
|
||||||
|
build_dir: ""
|
||||||
|
})
|
||||||
|
|> json_response_and_validate_schema(:ok)
|
||||||
|
|
||||||
|
ObanHelpers.perform(all_enqueued(worker: FrontendInstallerWorker))
|
||||||
|
|
||||||
|
assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue