diff --git a/.env.example b/.env.example index 0d614b5..a96398c 100644 --- a/.env.example +++ b/.env.example @@ -16,6 +16,10 @@ METRICS_PORT=9100 # Set to allow importing history straight from Last.fm (https://www.last.fm/api/account/create). LASTFM_API_KEY= +# Album art (MusicBrainz + Cover Art Archive, both free and keyless — no setup required). +# MusicBrainz asks for a contact URL/email in requests; falls back to UI_BASE_URL if unset. +MUSICBRAINZ_CONTACT= + # docker compose host ports (defaults shown) API_PORT=5050 UI_PORT=8080 diff --git a/deploy/nginx/default.conf.template b/deploy/nginx/default.conf.template index b128334..a532fe2 100644 --- a/deploy/nginx/default.conf.template +++ b/deploy/nginx/default.conf.template @@ -18,7 +18,7 @@ server { try_files $uri $uri/ =404; # Files aren't fingerprinted, so always revalidate. add_header Cache-Control "no-cache"; - add_header Content-Security-Policy "default-src 'self'; connect-src 'self' ${API_BASE_URL}; img-src 'self' data:; style-src 'self'; font-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'" always; + add_header Content-Security-Policy "default-src 'self'; connect-src 'self' ${API_BASE_URL}; img-src 'self' data: blob:; style-src 'self'; font-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'" always; add_header X-Content-Type-Options nosniff always; add_header Referrer-Policy same-origin always; } diff --git a/docker-compose.yml b/docker-compose.yml index a36c6b8..19e316f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,6 +34,7 @@ services: WEB_CONCURRENCY: ${WEB_CONCURRENCY:-2} FORWARDED_ALLOW_IPS: "*" LASTFM_API_KEY: ${LASTFM_API_KEY:-} + MUSICBRAINZ_CONTACT: ${MUSICBRAINZ_CONTACT:-} FEDERATION_ENABLED: ${FEDERATION_ENABLED:-0} FEDERATION_DOMAIN: ${FEDERATION_DOMAIN:-} FEDERATION_BASE_URL: ${FEDERATION_BASE_URL:-} diff --git a/docs/admin-guide.md b/docs/admin-guide.md index c081244..8d56c41 100644 --- a/docs/admin-guide.md +++ b/docs/admin-guide.md @@ -54,6 +54,7 @@ read **Putting it behind TLS** below — the quick start above serves plain HTTP | `WEB_CONCURRENCY` | api | `2` | gunicorn workers | | `RUN_MIGRATIONS` | api image | `1` | Apply database migrations on start | | `LASTFM_API_KEY` | api, worker | *(unset)* | Enables importing straight from Last.fm ([get a key](https://www.last.fm/api/account/create)) | +| `MUSICBRAINZ_CONTACT` | api | `UI_BASE_URL` | Contact URL/email sent to MusicBrainz for album art lookups (no key needed, but they ask for one) | | `IMPORT_MAX_BYTES` | api | 200 MB | Largest export file accepted | | `WORKER_METRICS_PORT` | worker | `9101` | The worker's Prometheus metrics port | | `API_BASE_URL` | ui image | `http://localhost:5050` | Where the browser reaches the API — written into `config.js` and the CSP | diff --git a/docs/openapi.json b/docs/openapi.json index 1492953..314f43e 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -1503,6 +1503,83 @@ } ] }, + "/api/v1/art/album": { + "get": { + "parameters": [ + { + "in": "query", + "name": "artist", + "schema": { + "type": "string", + "minLength": 1, + "maxLength": 500 + }, + "required": true + }, + { + "in": "query", + "name": "album", + "schema": { + "type": "string", + "minLength": 1, + "maxLength": 500 + }, + "required": true + } + ], + "responses": { + "422": { + "$ref": "#/components/responses/UNPROCESSABLE_CONTENT" + }, + "502": { + "description": "MusicBrainz or Cover Art Archive is unreachable", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "No cover art found for this album", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "200": { + "description": "The album's cover art" + }, + "401": { + "description": "Not authenticated", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "default": { + "$ref": "#/components/responses/DEFAULT_ERROR" + } + }, + "summary": "An album's cover art", + "description": "Resolved via MusicBrainz + Cover Art Archive and cached; bytes are proxied on every\ncall, so cache this response client-side.", + "tags": [ + "Art" + ], + "security": [ + { + "bearerAuth": [] + } + ] + } + }, "/healthz": { "get": { "responses": { @@ -3374,6 +3451,10 @@ "name": "Imports", "description": "Import listening history from a Last.fm export file, or straight from Last.fm. Imports run in the background; poll a job to follow its progress." }, + { + "name": "Art", + "description": "Album art, proxied from MusicBrainz / Cover Art Archive" + }, { "name": "Health", "description": "Liveness for load balancers and containers" diff --git a/frontend/css/style.css b/frontend/css/style.css index 065b60a..7b6f67d 100644 --- a/frontend/css/style.css +++ b/frontend/css/style.css @@ -1079,3 +1079,73 @@ input { margin: 0; font-weight: 600; } + +/* The song page's glowing display gets an art thumbnail alongside its text, when there's one */ +.display-with-art { + display: flex; + align-items: center; + gap: 1.25rem; +} + +.display-with-art .display-body { + flex: 1; + min-width: 0; +} + +.display-art { + width: 4.5rem; + height: 4.5rem; + flex: none; +} + +/* ---- Album art ---------------------------------------------------------------- */ +.art-thumb { + display: block; + border-radius: var(--radius-control); + object-fit: cover; + background: var(--paper-raised); + border: 1px solid var(--rule); +} + +.art-thumb-empty { + position: relative; +} + +/* No artwork: a plain ring, echoing .brand-mark's small round "lamp" motif */ +.art-thumb-empty::after { + content: ""; + position: absolute; + inset: 32%; + border-radius: 50%; + border: 2px solid var(--bar); +} + +/* Most played > Albums: a thumbnail column ahead of the rank */ +.ranking-art li { + grid-template-columns: 2.25rem 2rem minmax(0, 1fr) auto; +} + +.ranking-art .art-thumb { + width: 2.25rem; + height: 2.25rem; + align-self: center; /* .ranking li aligns its other cells to baseline, which suits text, not art */ +} + +.ranking-art .meter { + left: 5.75rem; +} + +/* Recently played / History: a thumbnail column ahead of the time */ +.log-art li { + grid-template-columns: 2.25rem 8rem minmax(0, 1fr); +} + +.log-art.log-clock li { + grid-template-columns: 2.25rem 3.5rem minmax(0, 1fr); +} + +.log-art .art-thumb { + width: 2.25rem; + height: 2.25rem; + align-self: center; /* .log li items default to stretch/start, which suits text, not art */ +} diff --git a/frontend/index.html b/frontend/index.html index be3c782..529e587 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -31,7 +31,7 @@