diff --git a/lib/livebook_web/live/open_live.ex b/lib/livebook_web/live/open_live.ex index 05852c757..81c12e617 100644 --- a/lib/livebook_web/live/open_live.ex +++ b/lib/livebook_web/live/open_live.ex @@ -159,12 +159,13 @@ defmodule LivebookWeb.OpenLive do def handle_params(%{"url" => url}, _url, socket) when socket.assigns.live_action == :public_import do origin = Notebook.ContentLoader.url_to_location(url) + files_url = Livebook.Utils.expand_url(url, "files/") origin |> Notebook.ContentLoader.fetch_content_from_location() |> case do {:ok, content} -> - socket = import_source(socket, content, origin: origin) + socket = import_source(socket, content, origin: origin, files_source: {:url, files_url}) {:noreply, socket} {:error, _message} -> diff --git a/test/livebook_web/live/open_live_test.exs b/test/livebook_web/live/open_live_test.exs index a0d0267f0..e8ac893ff 100644 --- a/test/livebook_web/live/open_live_test.exs +++ b/test/livebook_web/live/open_live_test.exs @@ -232,13 +232,23 @@ defmodule LivebookWeb.OpenLiveTest do end describe "public import endpoint" do - test "imports notebook from the given url and redirects to the new session", %{conn: conn} do + test "imports notebook from the given url and downloads its files", %{conn: conn} do bypass = Bypass.open() Bypass.expect_once(bypass, "GET", "/notebook", fn conn -> conn |> Plug.Conn.put_resp_content_type("text/plain") - |> Plug.Conn.resp(200, "# My notebook") + |> Plug.Conn.resp(200, """ + + + # My notebook + """) + end) + + Bypass.expect_once(bypass, "GET", "/files/image.jpg", fn conn -> + conn + |> Plug.Conn.put_resp_content_type("text/plain") + |> Plug.Conn.resp(200, "content") end) notebook_url = "http://localhost:#{bypass.port}/notebook" @@ -248,6 +258,12 @@ defmodule LivebookWeb.OpenLiveTest do {:ok, view, _} = live(conn, to) assert render(view) =~ "My notebook" + "/sessions/" <> session_id = to + {:ok, session} = Sessions.fetch_session(session_id) + + assert FileSystem.File.resolve(session.files_dir, "image.jpg") |> FileSystem.File.read() == + {:ok, "content"} + close_session_by_path(to) end