Change /covers to /assets
This commit is contained in:
@@ -21,7 +21,7 @@ defmodule MusicLibraryWeb.RecordComponents do
|
|||||||
<img
|
<img
|
||||||
class={@class}
|
class={@class}
|
||||||
alt={@record.title}
|
alt={@record.title}
|
||||||
src={~p"/covers/#{@payload}"}
|
src={~p"/assets/#{@payload}"}
|
||||||
/>
|
/>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ defmodule MusicLibraryWeb.ArtistController do
|
|||||||
|
|
||||||
alias MusicLibrary.Artists
|
alias MusicLibrary.Artists
|
||||||
alias MusicLibrary.Assets.Transform
|
alias MusicLibrary.Assets.Transform
|
||||||
alias MusicLibraryWeb.CoverController
|
alias MusicLibraryWeb.AssetController
|
||||||
|
|
||||||
def image(conn, %{"musicbrainz_id" => artist_id}) do
|
def image(conn, %{"musicbrainz_id" => artist_id}) do
|
||||||
case Artists.get_image(artist_id) do
|
case Artists.get_image(artist_id) do
|
||||||
@@ -15,7 +15,7 @@ defmodule MusicLibraryWeb.ArtistController do
|
|||||||
%Transform{hash: hash}
|
%Transform{hash: hash}
|
||||||
|> Transform.encode!()
|
|> Transform.encode!()
|
||||||
|
|
||||||
CoverController.show(conn, %{"transform_payload" => payload})
|
AssetController.show(conn, %{"transform_payload" => payload})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
defmodule MusicLibraryWeb.CoverController do
|
defmodule MusicLibraryWeb.AssetController do
|
||||||
use MusicLibraryWeb, :controller
|
use MusicLibraryWeb, :controller
|
||||||
|
|
||||||
alias MusicLibrary.Assets
|
alias MusicLibrary.Assets
|
||||||
@@ -21,8 +21,8 @@ defmodule MusicLibraryWeb.CollectionJSON do
|
|||||||
id: record.id,
|
id: record.id,
|
||||||
artists: Enum.map(record.artists, & &1.name),
|
artists: Enum.map(record.artists, & &1.name),
|
||||||
title: record.title,
|
title: record.title,
|
||||||
cover_url: url(~p"/api/covers/#{%Transform{hash: record.cover_hash}}"),
|
cover_url: url(~p"/api/assets/#{%Transform{hash: record.cover_hash}}"),
|
||||||
thumb_url: url(~p"/api/covers/#{%Transform{hash: record.cover_hash, width: 480}}")
|
thumb_url: url(~p"/api/assets/#{%Transform{hash: record.cover_hash, width: 480}}")
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ defmodule MusicLibraryWeb.Router do
|
|||||||
|
|
||||||
get "/backup", ArchiveController, :backup
|
get "/backup", ArchiveController, :backup
|
||||||
|
|
||||||
get "/covers/:transform_payload", CoverController, :show
|
get "/assets/:transform_payload", AssetController, :show
|
||||||
get "/artists/:musicbrainz_id/image", ArtistController, :image
|
get "/artists/:musicbrainz_id/image", ArtistController, :image
|
||||||
|
|
||||||
live_session :default,
|
live_session :default,
|
||||||
@@ -82,7 +82,7 @@ defmodule MusicLibraryWeb.Router do
|
|||||||
get "/collection/latest", CollectionController, :latest
|
get "/collection/latest", CollectionController, :latest
|
||||||
get "/collection/random", CollectionController, :random
|
get "/collection/random", CollectionController, :random
|
||||||
get "/collection", CollectionController, :index
|
get "/collection", CollectionController, :index
|
||||||
get "/covers/:transform_payload", CoverController, :show
|
get "/assets/:transform_payload", AssetController, :show
|
||||||
get "/backup", ArchiveController, :backup
|
get "/backup", ArchiveController, :backup
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -1,4 +1,4 @@
|
|||||||
defmodule MusicLibraryWeb.CoverControllerTest do
|
defmodule MusicLibraryWeb.AssetControllerTest do
|
||||||
use MusicLibraryWeb.ConnCase
|
use MusicLibraryWeb.ConnCase
|
||||||
|
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
@@ -12,21 +12,21 @@ defmodule MusicLibraryWeb.CoverControllerTest do
|
|||||||
%{asset: asset}
|
%{asset: asset}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /covers/:payload" do
|
describe "GET /assets/:payload" do
|
||||||
setup [:create_asset]
|
setup [:create_asset]
|
||||||
|
|
||||||
test "404s when asset doesn't exist", %{conn: conn} do
|
test "404s when asset doesn't exist", %{conn: conn} do
|
||||||
transform = %Transform{hash: Ecto.UUID.generate()}
|
transform = %Transform{hash: Ecto.UUID.generate()}
|
||||||
payload = Transform.encode!(transform)
|
payload = Transform.encode!(transform)
|
||||||
|
|
||||||
conn = get(conn, ~p"/covers/#{payload}")
|
conn = get(conn, ~p"/assets/#{payload}")
|
||||||
assert text_response(conn, 404) == "Not found"
|
assert text_response(conn, 404) == "Not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "serves the cover without etag", %{conn: conn, asset: asset} do
|
test "serves the asset without etag", %{conn: conn, asset: asset} do
|
||||||
transform = %Transform{hash: asset.hash}
|
transform = %Transform{hash: asset.hash}
|
||||||
payload = Transform.encode!(transform)
|
payload = Transform.encode!(transform)
|
||||||
conn = get(conn, ~p"/covers/#{payload}")
|
conn = get(conn, ~p"/assets/#{payload}")
|
||||||
|
|
||||||
assert conn.status == 200
|
assert conn.status == 200
|
||||||
assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"]
|
assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"]
|
||||||
@@ -36,14 +36,14 @@ defmodule MusicLibraryWeb.CoverControllerTest do
|
|||||||
assert conn.resp_body == asset.content
|
assert conn.resp_body == asset.content
|
||||||
end
|
end
|
||||||
|
|
||||||
test "serves the cover when etag doesn't match", %{conn: conn, asset: asset} do
|
test "serves the asset when etag doesn't match", %{conn: conn, asset: asset} do
|
||||||
transform = %Transform{hash: asset.hash}
|
transform = %Transform{hash: asset.hash}
|
||||||
payload = Transform.encode!(transform)
|
payload = Transform.encode!(transform)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("if-none-match", "invalid-etag")
|
|> put_req_header("if-none-match", "invalid-etag")
|
||||||
|> get(~p"/covers/#{payload}")
|
|> get(~p"/assets/#{payload}")
|
||||||
|
|
||||||
assert conn.status == 200
|
assert conn.status == 200
|
||||||
assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"]
|
assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"]
|
||||||
@@ -60,7 +60,7 @@ defmodule MusicLibraryWeb.CoverControllerTest do
|
|||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("if-none-match", payload)
|
|> put_req_header("if-none-match", payload)
|
||||||
|> get(~p"/covers/#{payload}")
|
|> get(~p"/assets/#{payload}")
|
||||||
|
|
||||||
assert conn.status == 304
|
assert conn.status == 304
|
||||||
assert get_resp_header(conn, "content-type") == []
|
assert get_resp_header(conn, "content-type") == []
|
||||||
@@ -74,7 +74,7 @@ defmodule MusicLibraryWeb.CoverControllerTest do
|
|||||||
transform = %Transform{hash: asset.hash, width: 480}
|
transform = %Transform{hash: asset.hash, width: 480}
|
||||||
payload = Transform.encode!(transform)
|
payload = Transform.encode!(transform)
|
||||||
|
|
||||||
conn = get(conn, ~p"/covers/#{payload}")
|
conn = get(conn, ~p"/assets/#{payload}")
|
||||||
|
|
||||||
assert conn.status == 200
|
assert conn.status == 200
|
||||||
assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"]
|
assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"]
|
||||||
@@ -32,9 +32,9 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
|||||||
"artists" => ["Steven Wilson"],
|
"artists" => ["Steven Wilson"],
|
||||||
"title" => record.title,
|
"title" => record.title,
|
||||||
"cover_url" =>
|
"cover_url" =>
|
||||||
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
||||||
"thumb_url" =>
|
"thumb_url" =>
|
||||||
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -60,9 +60,9 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
|||||||
"artists" => ["Steven Wilson"],
|
"artists" => ["Steven Wilson"],
|
||||||
"title" => record.title,
|
"title" => record.title,
|
||||||
"cover_url" =>
|
"cover_url" =>
|
||||||
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
||||||
"thumb_url" =>
|
"thumb_url" =>
|
||||||
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -92,9 +92,9 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
|||||||
"artists" => ["Steven Wilson"],
|
"artists" => ["Steven Wilson"],
|
||||||
"title" => record.title,
|
"title" => record.title,
|
||||||
"cover_url" =>
|
"cover_url" =>
|
||||||
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
||||||
"thumb_url" =>
|
"thumb_url" =>
|
||||||
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -446,6 +446,6 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
defp cover_url(record, width) do
|
defp cover_url(record, width) do
|
||||||
transform = %Transform{hash: record.cover_hash, width: width}
|
transform = %Transform{hash: record.cover_hash, width: width}
|
||||||
payload = Transform.encode!(transform)
|
payload = Transform.encode!(transform)
|
||||||
~p"/covers/#{payload}"
|
~p"/assets/#{payload}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|
|||||||
record = record()
|
record = record()
|
||||||
transform = %Transform{hash: record.cover_hash, width: nil}
|
transform = %Transform{hash: record.cover_hash, width: nil}
|
||||||
payload = Transform.encode!(transform)
|
payload = Transform.encode!(transform)
|
||||||
cover_url = ~p"/covers/#{payload}"
|
cover_url = ~p"/assets/#{payload}"
|
||||||
|
|
||||||
release_response = Fixtures.Release.release(:marbles)
|
release_response = Fixtures.Release.release(:marbles)
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
|
|||||||
record = record(purchased_at: nil)
|
record = record(purchased_at: nil)
|
||||||
transform = %Transform{hash: record.cover_hash, width: nil}
|
transform = %Transform{hash: record.cover_hash, width: nil}
|
||||||
payload = Transform.encode!(transform)
|
payload = Transform.encode!(transform)
|
||||||
cover_url = ~p"/covers/#{payload}"
|
cover_url = ~p"/assets/#{payload}"
|
||||||
|
|
||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|
|||||||
Reference in New Issue
Block a user