fix: iTunes route order (lookup before proxy); stable cover art URLs for browser caching
This commit is contained in:
1 parent
09cec18b33
commit
21159ad2c5
3 files changed
+45
-24
No files matched your search
+18
-1
@@ -28,12 +28,29 @@ export async function getLyricsBySongId(songId) {
|
||||
} catch { return []; }
|
||||
}
|
||||
export function downloadUrl(id) { return apiUrl('download', `&id=${id}`); }
|
||||
// Stable salt derived from credentials so the browser HTTP cache survives page reloads.
|
||||
// Random salt (apiUrl default) changes every session → cache miss every time → art re-fetches.
|
||||
let _coverSalt = null, _coverToken = null;
|
||||
function _coverAuth() {
|
||||
if (!_coverSalt && S.cfg.user && S.cfg.pass) {
|
||||
_coverSalt = md5(S.cfg.user + S.cfg.pass).slice(0, 8);
|
||||
_coverToken = md5(S.cfg.pass + _coverSalt);
|
||||
}
|
||||
return _coverSalt ? `u=${encodeURIComponent(S.cfg.user)}&t=${_coverToken}&s=${_coverSalt}` : null;
|
||||
}
|
||||
export function coverUrl(id, size=300) {
|
||||
if (!id) return null;
|
||||
const key = `${id}:${size}`;
|
||||
if (!_coverUrlCache.has(key)) _coverUrlCache.set(key, apiUrl('getCoverArt', `&id=${id}&size=${size}`));
|
||||
if (!_coverUrlCache.has(key)) {
|
||||
const auth = _coverAuth();
|
||||
const url = auth
|
||||
? `${S.cfg.url}/rest/getCoverArt?${auth}&v=1.16.1&c=NovaSonic&f=json&id=${id}&size=${size}`
|
||||
: apiUrl('getCoverArt', `&id=${id}&size=${size}`);
|
||||
_coverUrlCache.set(key, url);
|
||||
}
|
||||
return _coverUrlCache.get(key);
|
||||
}
|
||||
export function invalidateCoverCache() { _coverUrlCache.clear(); _coverSalt = null; _coverToken = null; }
|
||||
|
||||
// ─── NAVIDROME REST AUTH ───
|
||||
export async function ndAuth() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { S } from './state.js';
|
||||
import { esc, formatDur, toast } from './utils.js';
|
||||
import { api, coverUrl, ndAuth, fetchRomajiIndex, romajiConvert, romajiLookup, invalidateRomajiIndex } from './api.js';
|
||||
import { api, coverUrl, ndAuth, fetchRomajiIndex, romajiConvert, romajiLookup, invalidateRomajiIndex, invalidateCoverCache } from './api.js';
|
||||
import { THEMES, applyTheme, getCurrentThemeId } from './themes.js';
|
||||
// Circular imports — safe (only used inside function bodies)
|
||||
import { playQueue, dlSongLocal, toggleStar, togglePlay, renderQueue, syncNpStar, updateStarBtn, npToggleStar, playCurrent, _syncNpDirect, setPlayIcon, nativeInsertAt, refreshDisplayMode } from './player.js';
|
||||
@@ -78,7 +78,9 @@ export function saveSettings() {
|
||||
const pass = document.getElementById('s-pass').value;
|
||||
S.cfg.url = document.getElementById('s-url').value.trim().replace(/\/$/,'');
|
||||
S.cfg.user = document.getElementById('s-user').value.trim();
|
||||
const credChanged = S.cfg.url !== document.getElementById('s-url').value.trim().replace(/\/$/,'') || !!pass;
|
||||
if(pass) S.cfg.pass = pass;
|
||||
if(credChanged) invalidateCoverCache();
|
||||
S.cfg.lastfmKey = document.getElementById('s-lastfm').value.trim();
|
||||
S.cfg.backendUrl = document.getElementById('s-backend').value.trim().replace(/\/$/,'');
|
||||
S.cfg.showPlayCount = document.getElementById('s-show-playcount').classList.contains('on');
|
||||
|
||||
Reference in new issue
Block a user