mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-20 21:04:17 +08:00
Expand directory path when opened via CLI (#976)
This commit is contained in:
parent
12e2e7902f
commit
4681f98972
2 changed files with 10 additions and 6 deletions
|
@ -158,6 +158,7 @@ defmodule LivebookCLI.Server do
|
|||
|
||||
defp open_from_args(base_url, [url_or_file_or_dir]) do
|
||||
url = URI.parse(url_or_file_or_dir)
|
||||
path = Path.expand(url_or_file_or_dir)
|
||||
|
||||
cond do
|
||||
url.scheme in ~w(http https file) ->
|
||||
|
@ -165,15 +166,15 @@ defmodule LivebookCLI.Server do
|
|||
|> Livebook.Utils.notebook_import_url(url_or_file_or_dir)
|
||||
|> Livebook.Utils.browser_open()
|
||||
|
||||
File.regular?(url_or_file_or_dir) ->
|
||||
File.regular?(path) ->
|
||||
base_url
|
||||
|> append_path("open")
|
||||
|> update_query(%{"path" => url_or_file_or_dir})
|
||||
|> update_query(%{"path" => path})
|
||||
|> Livebook.Utils.browser_open()
|
||||
|
||||
File.dir?(url_or_file_or_dir) ->
|
||||
File.dir?(path) ->
|
||||
base_url
|
||||
|> update_query(%{"path" => url_or_file_or_dir})
|
||||
|> update_query(%{"path" => path})
|
||||
|> Livebook.Utils.browser_open()
|
||||
|
||||
true ->
|
||||
|
|
|
@ -61,19 +61,22 @@ defmodule LivebookWeb.AuthPlug do
|
|||
end
|
||||
|
||||
defp authenticate(conn, :token) do
|
||||
token = Map.get(conn.query_params, "token")
|
||||
{token, query_params} = Map.pop(conn.query_params, "token")
|
||||
|
||||
if is_binary(token) and Plug.Crypto.secure_compare(hash(token), expected(:token)) do
|
||||
# Redirect to the same path without query params
|
||||
conn
|
||||
|> store(:token, token)
|
||||
|> redirect(to: conn.request_path)
|
||||
|> redirect(to: path_with_query(conn.request_path, query_params))
|
||||
|> halt()
|
||||
else
|
||||
raise LivebookWeb.InvalidTokenError
|
||||
end
|
||||
end
|
||||
|
||||
defp path_with_query(path, params) when params == %{}, do: path
|
||||
defp path_with_query(path, params), do: path <> "?" <> URI.encode_query(params)
|
||||
|
||||
defp key(port, mode), do: "#{port}:#{mode}"
|
||||
defp expected(mode), do: hash(Application.fetch_env!(:livebook, mode))
|
||||
defp hash(value), do: :crypto.hash(:sha256, value)
|
||||
|
|
Loading…
Reference in a new issue