Server records on this day email assets from a public endpoint

This commit is contained in:
Claudio Ortolina
2026-03-05 10:50:35 +00:00
parent c1422956c0
commit 73a943bc63
3 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -288,7 +288,7 @@ All authenticated routes live inside a single `live_session` with three `on_moun
| `HealthController` | `/health` | Health check |
| `LastFmController` | `/auth/last_fm/callback` | Last.fm OAuth |
| `ArchiveController` | `/backup`, `/api/backup` | Database backup download (API route requires token) |
| `AssetController` | `/assets/:transform_payload`, `/api/assets/:transform_payload` | Serve images with transforms (API route requires token) |
| `AssetController` | `/assets/:transform_payload`, `/public/assets/:transform_payload`, `/api/assets/:transform_payload` | Serve images with transforms (public route for emails, API route requires token) |
| `CollectionController` | `/api/collection/*` | JSON API for collection queries |
---
@@ -44,11 +44,10 @@ defmodule MusicLibrary.RecordsOnThisDayEmail do
defp build_html(records, date, conf) do
base_url = Keyword.fetch!(conf, :base_url) |> String.trim_trailing("/")
api_token = Application.get_env(:music_library, MusicLibraryWeb)[:api_token]
heading = date |> Calendar.strftime("Records on %-d %B") |> html_escape()
records_html =
Enum.map_join(records, "\n", fn record -> record_html(record, date, base_url, api_token) end)
Enum.map_join(records, "\n", fn record -> record_html(record, date, base_url) end)
"""
<div style="max-width: 600px; margin: 0 auto; padding: 20px; font-family: system-ui, -apple-system, sans-serif; background-color: #f4f4f5;">
@@ -62,9 +61,9 @@ defmodule MusicLibrary.RecordsOnThisDayEmail do
"""
end
defp record_html(record, date, base_url, api_token) do
defp record_html(record, date, base_url) do
years = Record.released_how_long_ago?(record, date)
cover_url = cover_image_url(record, base_url, api_token)
cover_url = cover_image_url(record, base_url)
record_url = record_detail_url(record, base_url)
artist_names = record |> Record.artist_names() |> html_escape()
title = record.title |> html_escape()
@@ -106,11 +105,11 @@ defmodule MusicLibrary.RecordsOnThisDayEmail do
"#{base_url}/collection/#{record.id}"
end
defp cover_image_url(%{cover_hash: nil}, _base_url, _api_token), do: nil
defp cover_image_url(%{cover_hash: nil}, _base_url), do: nil
defp cover_image_url(record, base_url, api_token) do
defp cover_image_url(record, base_url) do
payload = Transform.new(hash: record.cover_hash, width: 96) |> Transform.encode!()
"#{base_url}/api/assets/#{payload}?token=#{api_token}"
"#{base_url}/public/assets/#{payload}"
end
defp years_ago_label(nil), do: ""
+2
View File
@@ -32,6 +32,8 @@ defmodule MusicLibraryWeb.Router do
get "/auth/last_fm/callback", LastFmController, :callback
get "/public/assets/:transform_payload", AssetController, :show
scope "/" do
pipe_through :logged_in