Stop rendering images from the legacy images directory

This commit is contained in:
Jonatan Kłosko 2024-01-26 21:07:14 +08:00
parent 83213b6056
commit f9f8579ca4
3 changed files with 0 additions and 50 deletions

View file

@ -26,20 +26,6 @@ defmodule LivebookWeb.SessionController do
end)
end
# Legacy endpoint for resolving images/
# TODO: remove on Livebook v0.12
def show_image(conn, %{"id" => id, "name" => name}) do
case Sessions.fetch_session(id) do
{:ok, session} ->
images_dir = FileSystem.File.resolve(session.files_dir, "../images/")
file = FileSystem.File.resolve(images_dir, name)
serve_static(conn, file)
{:error, _} ->
send_resp(conn, 404, "Not found")
end
end
def download_file(conn, %{"id" => id, "name" => name}) do
with {:ok, session} <- Sessions.fetch_session(id),
{:ok, path} <- Session.fetch_file_entry_path(session.pid, name) do

View file

@ -119,7 +119,6 @@ defmodule LivebookWeb.Router do
live "/sessions/:id/insert-file", SessionLive, :insert_file
live "/sessions/:id/package-search", SessionLive, :package_search
get "/sessions/:id/files/:name", SessionController, :show_file
get "/sessions/:id/images/:name", SessionController, :show_image
get "/sessions/:id/download/files/:name", SessionController, :download_file
get "/sessions/audio-input/:token", SessionController, :show_input_audio
get "/sessions/image-input/:token", SessionController, :show_input_image

View file

@ -68,41 +68,6 @@ defmodule LivebookWeb.SessionControllerTest do
end
end
# Legacy endpoint for resolving images/
describe "show_image" do
test "returns not found when the given session does not exist", %{conn: conn} do
id = Livebook.Utils.random_node_aware_id()
conn = get(conn, ~p"/sessions/#{id}/images/image.jpg")
assert conn.status == 404
assert conn.resp_body == "Not found"
end
test "returns not found when the given image does not exist", %{conn: conn} do
{:ok, session} = Sessions.create_session()
conn = get(conn, ~p"/sessions/#{session.id}/images/nonexistent.jpg")
assert conn.status == 404
assert conn.resp_body == "No such file or directory"
Session.close(session.pid)
end
test "returns the image when it does exist", %{conn: conn} do
{:ok, session} = Sessions.create_session()
images_dir = FileSystem.File.resolve(session.files_dir, "../images/")
:ok = FileSystem.File.resolve(images_dir, "test.jpg") |> FileSystem.File.write("")
conn = get(conn, ~p"/sessions/#{session.id}/images/test.jpg")
assert conn.status == 200
assert get_resp_header(conn, "content-type") == ["image/jpeg"]
Session.close(session.pid)
end
end
describe "download_file" do
test "returns not found when the given session does not exist", %{conn: conn} do
id = Livebook.Utils.random_node_aware_id()