diff options
author | Roman Chvanikov <chvanikoff@pm.me> | 2020-07-11 14:09:11 +0300 |
---|---|---|
committer | Roman Chvanikov <chvanikoff@pm.me> | 2020-07-11 14:09:11 +0300 |
commit | f7464724f5d5ae84fac3bc7291d2bb352ace6fdf (patch) | |
tree | 84164a848232174239cd9f765ba6035c4beafc19 | |
parent | 8f8a3f4f0174342680a2821247612ec4eae2cc37 (diff) | |
download | pleroma-f7464724f5d5ae84fac3bc7291d2bb352ace6fdf.tar.gz |
fix Pleroma.Frontend logic
-rw-r--r-- | lib/mix/tasks/pleroma/frontend.ex | 83 |
1 files changed, 24 insertions, 59 deletions
diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex index 03169c8b8..7089b899c 100644 --- a/lib/mix/tasks/pleroma/frontend.ex +++ b/lib/mix/tasks/pleroma/frontend.ex @@ -46,11 +46,22 @@ defmodule Mix.Tasks.Pleroma.Frontend do OptionParser.parse( args, strict: [ - ref: :string + ref: :string, + develop: :boolean ] ) - ref = suggest_ref(options, frontend) + ref = + cond do + options[:develop] -> + "develop" + + options[:ref] -> + options[:ref] + + true -> + "stable" + end %{"name" => bundle_name, "url" => bundle_url} = get_bundle_meta(ref, @pleroma_gitlab_host, @frontends[frontend]["project"]) @@ -83,56 +94,6 @@ defmodule Mix.Tasks.Pleroma.Frontend do defp post_install_bundle(_fe_name, _path), do: :ok - defp suggest_ref(options, frontend) do - case Pleroma.Config.get([:frontends, String.to_atom(frontend)]) do - nil -> - primary_fe_config = Pleroma.Config.get([:frontends, :primary]) - - if primary_fe_config["name"] == frontend do - primary_fe_config["ref"] - else - nil - end - - val -> - val - end - |> case do - nil -> - stable_pleroma? = Pleroma.Application.stable?() - - current_stable_out = - if stable_pleroma? do - "stable" - else - "develop" - end - - get_option( - options, - :ref, - "You are currently running #{current_stable_out} version of Pleroma backend. What version of \"#{ - frontend - }\" frontend you want to install? (\"stable\", \"develop\" or specific ref)", - current_stable_out - ) - - config_value -> - current_ref = - case config_value do - %{"ref" => ref} -> ref - ref -> ref - end - - get_option( - options, - :ref, - "You are currently running \"#{current_ref}\" version of \"#{frontend}\" frontend. What version do you want to install? (\"stable\", \"develop\" or specific ref)", - current_ref - ) - end - end - defp get_bundle_meta("develop", gitlab_base_url, project) do url = "#{gitlab_api_url(gitlab_base_url, project)}/repository/branches" @@ -175,15 +136,16 @@ defmodule Mix.Tasks.Pleroma.Frontend do http_client = http_client() with {:ok, %{status: 200, body: zip_body}} <- Tesla.get(http_client, bundle_url), - {:ok, unzipped} <- :zip.unzip(zip_body, [:memory]) do + {:ok, unzipped} <- :zip.unzip(zip_body, [:memory]), + filtered = + Enum.filter(unzipped, fn + {[?d, ?i, ?s, ?t, ?/ | _rest], _data} -> true + _ -> false + end), + true <- length(filtered) > 0 do File.rm_rf!(dir) - Enum.each(unzipped, fn {path, data} -> - path = - path - |> to_string() - |> String.replace(~r/^dist\//, "") - + Enum.each(unzipped, fn {[?d, ?i, ?s, ?t, ?/ | path], data} -> file_path = Path.join(dir, path) file_path @@ -196,6 +158,9 @@ defmodule Mix.Tasks.Pleroma.Frontend do {:ok, %{status: 404}} -> {:error, "Bundle not found"} + false -> + {:error, "Zip archive must contain \"dist\" folder"} + error -> {:error, error} end |