fix: album cards use romaji index for album name display via _albumRomajiMap
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
52f5385988
commit
45cb62198e
2 files changed
+11
-3
No files matched your search
+7
-2
@@ -71,16 +71,20 @@ export async function ndAuth() {
|
||||
let _romajiIndex = null;
|
||||
let _romajiMap = null; // Map<songId, { titleRomaji, artistRomaji, albumRomaji }>
|
||||
let _artistRomajiMap = null; // Map<artistId, artistRomaji>
|
||||
let _albumRomajiMap = null; // Map<albumName(JP), albumRomaji> — 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.
|
||||
|
||||
+4
-1
@@ -281,7 +281,10 @@ export async function loadAlbumRow(id, method, extra) {
|
||||
if(!c) return;
|
||||
c.innerHTML = '<div class="spinner"></div>';
|
||||
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 = `<div style="color:var(--text3);font-size:13px;padding:16px">${e.message}</div>`; }
|
||||
|
||||
Reference in new issue
Block a user