Serve local cover images
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
defmodule MusicLibraryWeb.ImageController do
|
||||
use MusicLibraryWeb, :controller
|
||||
|
||||
alias MusicLibrary.Records
|
||||
|
||||
def show(conn, %{"record_id" => record_id}) do
|
||||
{:ok, image_data} = Records.get_image!(record_id)
|
||||
|
||||
if image_data do
|
||||
conn
|
||||
|> put_resp_content_type("image/jpeg", "utf-8")
|
||||
|> send_resp(200, image_data)
|
||||
else
|
||||
conn |> send_resp(404, "Not found")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -36,7 +36,7 @@ defmodule MusicLibraryWeb.RecordLive.FormComponent do
|
||||
label="Genres"
|
||||
options={[{"Option 1", "option1"}, {"Option 2", "option2"}]}
|
||||
/>
|
||||
<.input field={@form[:image]} type="text" label="Image" />
|
||||
<.input field={@form[:image_url]} type="text" label="Image url" />
|
||||
<:actions>
|
||||
<.button phx-disable-with="Saving...">Save Record</.button>
|
||||
</:actions>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
row_click={fn {_id, record} -> JS.navigate(~p"/records/#{record}") end}
|
||||
>
|
||||
<:col :let={{_id, record}} label="Image">
|
||||
<img class="max-w-16" src={record.image} alt={record.title} />
|
||||
<img class="max-w-16" src={~p"/images/#{record.id}"} alt={record.title} />
|
||||
</:col>
|
||||
<:col :let={{_id, record}} label="Artists">
|
||||
<%= Enum.map(record.artists, fn a -> a.name end) %>
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
<:item title="Musicbrainz"><%= @record.musicbrainz_id %></:item>
|
||||
<:item title="Year"><%= @record.year %></:item>
|
||||
<:item title="Genres"><%= @record.genres %></:item>
|
||||
<:item title="Image"><%= @record.image %></:item>
|
||||
<:item title="Image">
|
||||
<img class="max-w-32" src={~p"/images/#{@record.id}"} alt={@record.title} />
|
||||
</:item>
|
||||
</.list>
|
||||
|
||||
<.back navigate={~p"/records"}>Back to records</.back>
|
||||
|
||||
@@ -18,6 +18,7 @@ defmodule MusicLibraryWeb.Router do
|
||||
pipe_through :browser
|
||||
|
||||
get "/", PageController, :home
|
||||
get "/images/:record_id", ImageController, :show
|
||||
|
||||
live "/records", RecordLive.Index, :index
|
||||
live "/records/new", RecordLive.Index, :new
|
||||
|
||||
Reference in New Issue
Block a user