Store image hashes in the db - part 2
This commit is contained in:
@@ -58,7 +58,7 @@ defmodule MusicLibrary.Records do
|
|||||||
q =
|
q =
|
||||||
from r in Record,
|
from r in Record,
|
||||||
where: r.id == ^id,
|
where: r.id == ^id,
|
||||||
select: r.image_data
|
select: %{image_data: r.image_data, image_data_hash: r.image_data_hash}
|
||||||
|
|
||||||
Repo.one!(q)
|
Repo.one!(q)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,10 +8,7 @@ defmodule MusicLibraryWeb.ImageController do
|
|||||||
nil ->
|
nil ->
|
||||||
send_resp(conn, 404, "Not found")
|
send_resp(conn, 404, "Not found")
|
||||||
|
|
||||||
image_data ->
|
%{image_data: image_data, image_data_hash: etag} ->
|
||||||
# TODO: move hash result to database
|
|
||||||
etag = :crypto.hash(:sha256, image_data) |> Base.encode16()
|
|
||||||
|
|
||||||
case get_req_header(conn, "if-none-match") do
|
case get_req_header(conn, "if-none-match") do
|
||||||
[^etag] ->
|
[^etag] ->
|
||||||
send_resp(conn, 304, "")
|
send_resp(conn, 304, "")
|
||||||
|
|||||||
Reference in New Issue
Block a user