From 45cb62198e8e94d3f9f736c22968fda7b5634a85 Mon Sep 17 00:00:00 2001 From: Honey Date: Sat, 6 Jun 2026 01:10:38 +0200 Subject: [PATCH] fix: album cards use romaji index for album name display via _albumRomajiMap Co-Authored-By: Claude Sonnet 4.6 --- src/api.js | 11 ++++++++--- src/views.js | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/api.js b/src/api.js index 8cf0e58..8c56f2f 100644 --- a/src/api.js +++ b/src/api.js @@ -69,18 +69,22 @@ export async function ndAuth() { // ─── ROMAJI INDEX ─── // Fetched once per session from the backend, cached in memory. let _romajiIndex = null; -let _romajiMap = null; // Map +let _romajiMap = null; // Map let _artistRomajiMap = null; // Map +let _albumRomajiMap = null; // Map — for album cards without song ID let _romajiIndexFetch = null; // in-flight promise dedup function _buildRomajiMap(idx) { const m = new Map(); const am = new Map(); + const bm = new Map(); if (Array.isArray(idx)) idx.forEach(e => { m.set(String(e.id), e); if (e.artistId && e.artistRomaji) am.set(String(e.artistId), e.artistRomaji); + if (e.album && e.albumRomaji && !bm.has(e.album)) bm.set(e.album, e.albumRomaji); }); _artistRomajiMap = am; + _albumRomajiMap = bm; return m; } @@ -96,7 +100,7 @@ export async function fetchRomajiIndex() { return _romajiIndexFetch; } -export function invalidateRomajiIndex() { _romajiIndex = null; _romajiMap = null; _artistRomajiMap = null; } +export function invalidateRomajiIndex() { _romajiIndex = null; _romajiMap = null; _artistRomajiMap = null; _albumRomajiMap = null; } // ─── ROMAJI OVERRIDES ─── // Stored server-side (shared across all clients). Cached in memory per session. @@ -144,7 +148,8 @@ export function dispArtistById(id, name) { export function dispAlbumName(name) { if (!S.cfg.showRomaji) return name || ''; const ov = getRomajiOverrides(); - return ov[name] || name || ''; + if (name && ov[name]) return ov[name]; + return _albumRomajiMap?.get(name) || name || ''; } // Synchronous lookup — returns index entry for a song ID, or null if not in index. diff --git a/src/views.js b/src/views.js index be2f8a7..247590f 100644 --- a/src/views.js +++ b/src/views.js @@ -281,7 +281,10 @@ export async function loadAlbumRow(id, method, extra) { if(!c) return; c.innerHTML = '
'; try { - const r = await api(method, extra); + const [r] = await Promise.all([ + api(method, extra), + S.cfg.showRomaji ? fetchRomajiIndex().catch(() => {}) : Promise.resolve(), + ]); c.innerHTML = ''; (r.albumList2?.album || []).forEach(a => c.appendChild(makeAlbumCard(a))); } catch(e) { c.innerHTML = `
${e.message}
`; }