@vicyangorg/dsh-music 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/index.js +167 -27
- package/docs/assets/library-shelf.webp +0 -0
- package/docs/assets/liked-full.webp +0 -0
- package/docs/assets/shelf-synced.webp +0 -0
- package/host/metadata/artist.js +25 -5
- package/host/reco/index.js +17 -4
- package/host/reco/verify.js +26 -1
- package/package.json +1 -1
package/client/index.js
CHANGED
|
@@ -96,6 +96,13 @@ window.__ModuleLoader__.load({
|
|
|
96
96
|
lang_pt: '葡萄牙语',
|
|
97
97
|
lang_it: '意大利语',
|
|
98
98
|
welcomeTasteNote: '偏好只用于微调探索批次,不会锁死你的推荐;之后随时能改。',
|
|
99
|
+
favsTitle: '我喜欢',
|
|
100
|
+
favsViewAll: '查看全部',
|
|
101
|
+
favsBack: '返回曲库',
|
|
102
|
+
favsEmpty: '还没有喜欢的歌——点任意歌曲的 ♥,它就会进入这里。',
|
|
103
|
+
artistReadyToast: '歌手页已就绪',
|
|
104
|
+
pageReadyToast: '页面已加载完成',
|
|
105
|
+
closeNotice: '关闭提示',
|
|
99
106
|
libTabsLabel: '曲库视图',
|
|
100
107
|
libTabLibrary: '曲库',
|
|
101
108
|
libTabLikes: '我喜欢',
|
|
@@ -261,7 +268,7 @@ window.__ModuleLoader__.load({
|
|
|
261
268
|
modeCycleHint: '点击切换播放模式',
|
|
262
269
|
modeHintShuffle: '随机播放:每轮打乱不重复',
|
|
263
270
|
artistPageBack: '返回推荐',
|
|
264
|
-
artistSongs: '
|
|
271
|
+
artistSongs: '歌曲',
|
|
265
272
|
artistLoading: '正在打开歌手页…',
|
|
266
273
|
artistError: '歌手页加载失败',
|
|
267
274
|
artistNoSongs: '这位歌手暂时没有已核实的歌曲。',
|
|
@@ -355,6 +362,13 @@ window.__ModuleLoader__.load({
|
|
|
355
362
|
lang_pt: 'Portuguese',
|
|
356
363
|
lang_it: 'Italian',
|
|
357
364
|
welcomeTasteNote: 'Preferences only bias the discovery batch - nothing is locked, and you can change them any time.',
|
|
365
|
+
favsTitle: 'Liked',
|
|
366
|
+
favsViewAll: 'View all',
|
|
367
|
+
favsBack: 'Back to library',
|
|
368
|
+
favsEmpty: 'No liked songs yet — hit the heart on any song and it lands here.',
|
|
369
|
+
artistReadyToast: 'Artist page ready',
|
|
370
|
+
pageReadyToast: 'Page ready',
|
|
371
|
+
closeNotice: 'Dismiss',
|
|
358
372
|
libTabsLabel: 'Library views',
|
|
359
373
|
libTabLibrary: 'Library',
|
|
360
374
|
libTabLikes: 'Liked',
|
|
@@ -520,7 +534,7 @@ window.__ModuleLoader__.load({
|
|
|
520
534
|
modeCycleHint: 'Click to switch play mode',
|
|
521
535
|
modeHintShuffle: 'Shuffle: random each pass, no repeats',
|
|
522
536
|
artistPageBack: 'Back to recommendations',
|
|
523
|
-
artistSongs: '
|
|
537
|
+
artistSongs: 'Songs',
|
|
524
538
|
artistLoading: 'Opening artist page…',
|
|
525
539
|
artistError: 'Artist page failed to load',
|
|
526
540
|
artistNoSongs: 'No verified songs for this artist yet.',
|
|
@@ -831,6 +845,26 @@ window.__ModuleLoader__.load({
|
|
|
831
845
|
.dshm-libtabs-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary);}
|
|
832
846
|
.dshm-libtabs-on{background:var(--dsw-alias-interactive-bg-active);color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2);font-weight:600;}
|
|
833
847
|
.dshm-libtabs-count{font-size:10.5px;color:var(--dsw-alias-label-tertiary);background:var(--dsw-alias-bg-layer-1);border-radius:999px;padding:0 6px;line-height:16px;}
|
|
848
|
+
.dshm-favs{padding:10px 20px 2px;width:100%;max-width:1120px;margin:0 auto;flex:none;box-sizing:border-box;}
|
|
849
|
+
.dshm-favs-head{display:flex;align-items:center;gap:8px;margin-bottom:8px;}
|
|
850
|
+
.dshm-favs-title{font-size:12.5px;font-weight:600;color:var(--dsw-alias-label-primary);}
|
|
851
|
+
.dshm-favs-all{margin-left:auto;}
|
|
852
|
+
.dshm-favs-empty{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--dsw-alias-label-tertiary);padding:10px 12px;border:1px dashed var(--dsw-alias-border-l1);border-radius:10px;}
|
|
853
|
+
.dshm-favs-rail{display:flex;gap:10px;overflow-x:auto;padding:2px 0 10px;scrollbar-width:thin;}
|
|
854
|
+
.dshm-favcard{appearance:none;border:0;background:transparent;padding:0;width:104px;flex:none;display:flex;flex-direction:column;gap:6px;cursor:pointer;text-align:left;color:inherit;font:inherit;}
|
|
855
|
+
.dshm-favcard-cover{position:relative;display:block;width:104px;height:104px;border-radius:12px;overflow:hidden;background:var(--dsw-alias-bg-layer-2);}
|
|
856
|
+
.dshm-favcard-heart{position:absolute;top:6px;right:6px;display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;border-radius:50%;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-state-error-primary);}
|
|
857
|
+
.dshm-favcard-title{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary);}
|
|
858
|
+
.dshm-favcard-sub{font-size:11px;color:var(--dsw-alias-label-tertiary);}
|
|
859
|
+
.dshm-favcard:hover .dshm-favcard-cover{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px;}
|
|
860
|
+
.dshm-favcard-off{opacity:.5;cursor:not-allowed;}
|
|
861
|
+
.dshm-favcard-more{height:104px;justify-content:center;align-items:center;gap:6px;border-radius:12px;border:1px dashed var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary);}
|
|
862
|
+
.dshm-favcard-more-label{font-size:11.5px;}
|
|
863
|
+
.dshm-toast{position:fixed;right:20px;bottom:96px;z-index:1000;display:flex;align-items:center;gap:8px;padding:8px 10px 8px 12px;border-radius:10px;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);box-shadow:0 6px 20px var(--dsw-alias-border-l2);font-size:12.5px;color:var(--dsw-alias-label-primary);animation:dshm-fade-in .18s ease-out;}
|
|
864
|
+
.dshm-toast-icon{display:inline-flex;color:var(--dsw-alias-state-success-primary);}
|
|
865
|
+
.dshm-toast-main{appearance:none;border:0;background:transparent;color:var(--dsw-alias-brand-text);font:inherit;cursor:pointer;padding:2px 4px;border-radius:6px;}
|
|
866
|
+
.dshm-toast-main:hover{background:var(--dsw-alias-interactive-bg-hover);}
|
|
867
|
+
.dshm-toast-x{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer;padding:4px;border-radius:6px;display:inline-flex;}
|
|
834
868
|
.dshm-search{display:flex;align-items:center;gap:8px;flex:1;min-width:180px;max-width:340px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:9px;padding:6px 10px;color:var(--dsw-alias-label-tertiary);transition:border-color .15s;}
|
|
835
869
|
.dshm-search:focus-within{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-secondary);}
|
|
836
870
|
.dshm-search input{flex:1;min-width:0;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;outline:none;}
|
|
@@ -1345,6 +1379,44 @@ window.__ModuleLoader__.load({
|
|
|
1345
1379
|
return { source: store, load };
|
|
1346
1380
|
}
|
|
1347
1381
|
|
|
1382
|
+
/* Artist page loader (v9): loads run to completion even when the user
|
|
1383
|
+
* navigates away, results are cached for the whole session (reopening is
|
|
1384
|
+
* instant) and every finished load is announced through lastReady so the
|
|
1385
|
+
* panel can toast "artist page ready" with a one-click shortcut. */
|
|
1386
|
+
function createArtistPageService(api) {
|
|
1387
|
+
const store = createStore({ pages: {}, loading: {}, lastReady: null, error: null });
|
|
1388
|
+
const pending = new Map();
|
|
1389
|
+
const keyOf = (name) => normalizeZh(name || '').trim();
|
|
1390
|
+
function load(name) {
|
|
1391
|
+
if (!name) return Promise.resolve(null);
|
|
1392
|
+
const key = keyOf(name);
|
|
1393
|
+
const snap = store.getSnapshot();
|
|
1394
|
+
if (snap.pages[key]) return Promise.resolve(snap.pages[key]);
|
|
1395
|
+
if (pending.has(key)) return pending.get(key);
|
|
1396
|
+
store.set({ loading: { ...store.getSnapshot().loading, [key]: true } });
|
|
1397
|
+
const p = api.recoArtist(name)
|
|
1398
|
+
.then((data) => {
|
|
1399
|
+
const cur = store.getSnapshot();
|
|
1400
|
+
store.set({
|
|
1401
|
+
pages: { ...cur.pages, [key]: data },
|
|
1402
|
+
loading: { ...cur.loading, [key]: false },
|
|
1403
|
+
error: null,
|
|
1404
|
+
lastReady: { name, key, at: Date.now() },
|
|
1405
|
+
});
|
|
1406
|
+
return data;
|
|
1407
|
+
})
|
|
1408
|
+
.catch((err) => {
|
|
1409
|
+
const cur = store.getSnapshot();
|
|
1410
|
+
store.set({ loading: { ...cur.loading, [key]: false }, error: (err && err.message) || String(err) });
|
|
1411
|
+
throw err;
|
|
1412
|
+
})
|
|
1413
|
+
.finally(() => { pending.delete(key); });
|
|
1414
|
+
pending.set(key, p);
|
|
1415
|
+
return p;
|
|
1416
|
+
}
|
|
1417
|
+
return { source: store, load, keyOf };
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1348
1420
|
/* Artist portraits (batch 2, v6): one lightweight image lookup per name.
|
|
1349
1421
|
* Requests are coalesced in a 150ms window and limited to 3 in flight, so a
|
|
1350
1422
|
* page that renders 20 artist rows does not fire 20 parallel lookups.
|
|
@@ -1668,6 +1740,9 @@ window.__ModuleLoader__.load({
|
|
|
1668
1740
|
if (liked && res && res.disliked === false) delete dislikes[key];
|
|
1669
1741
|
store.set({ keys, dislikes });
|
|
1670
1742
|
if (res && res.downloading && onAutoDownload) onAutoDownload();
|
|
1743
|
+
/* Refresh the cached lists so the library card rail reflects the new
|
|
1744
|
+
* heart immediately (host is the source of truth, call is local). */
|
|
1745
|
+
load();
|
|
1671
1746
|
return res || {};
|
|
1672
1747
|
}
|
|
1673
1748
|
async function setDislike(item, disliked) {
|
|
@@ -2702,18 +2777,46 @@ window.__ModuleLoader__.load({
|
|
|
2702
2777
|
return h(React.Fragment, null,
|
|
2703
2778
|
sync ? h(SyncPanel, { t, sync, useSync }) : null,
|
|
2704
2779
|
rowError ? h('div', { className: 'dshm-errorline', role: 'alert', style: { margin: '8px 24px 0' } }, rowError) : null,
|
|
2705
|
-
|
|
2706
|
-
h('
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2780
|
+
libTab === 'likes'
|
|
2781
|
+
? h('div', { className: 'dshm-libtabs' },
|
|
2782
|
+
h('button', {
|
|
2783
|
+
type: 'button', className: 'dshm-chipbtn',
|
|
2784
|
+
onClick: () => setLibTab('library'),
|
|
2785
|
+
}, '← ' + t('favsBack')),
|
|
2786
|
+
h('span', { className: 'dshm-favs-title', style: { marginLeft: '4px' } }, t('libTabLikes')),
|
|
2787
|
+
h('span', { className: 'dshm-count' }, likeItems.length + ' ' + t('tracksUnit')))
|
|
2788
|
+
: h('div', { className: 'dshm-favs' },
|
|
2789
|
+
h('div', { className: 'dshm-favs-head' },
|
|
2790
|
+
h(IconHeart, { size: 14, style: { color: 'var(--dsw-alias-state-error-primary)' } }),
|
|
2791
|
+
h('span', { className: 'dshm-favs-title' }, t('favsTitle')),
|
|
2792
|
+
likeItems.length ? h('span', { className: 'dshm-count' }, likeItems.length + ' ' + t('tracksUnit')) : null,
|
|
2793
|
+
likeItems.length
|
|
2794
|
+
? h('button', {
|
|
2795
|
+
type: 'button', className: 'dshm-chipbtn dshm-favs-all',
|
|
2796
|
+
onClick: () => setLibTab('likes'),
|
|
2797
|
+
}, t('favsViewAll'), ' ›')
|
|
2798
|
+
: null),
|
|
2799
|
+
likeItems.length === 0
|
|
2800
|
+
? h('div', { className: 'dshm-favs-empty' }, h(IconHeart, { size: 16 }), t('favsEmpty'))
|
|
2801
|
+
: h('div', { className: 'dshm-favs-rail' },
|
|
2802
|
+
likedTracks.slice(0, 12).map((tr, i) => h('button', {
|
|
2803
|
+
key: tr.id || ('fav' + i), type: 'button',
|
|
2804
|
+
className: cx('dshm-favcard', tr.muted && 'dshm-favcard-off'),
|
|
2805
|
+
title: tr.muted ? t('topUnplayable') : (tr.title || '') + (tr.artist ? ' · ' + tr.artist : ''),
|
|
2806
|
+
onClick: () => playLiked(tr),
|
|
2807
|
+
},
|
|
2808
|
+
h('span', { className: 'dshm-favcard-cover' },
|
|
2809
|
+
h(Thumb, { src: tr.coverUrl, size: 96 }),
|
|
2810
|
+
h('span', { className: 'dshm-favcard-heart' }, h(IconHeart, { size: 11, style: { fill: 'currentColor' } }))),
|
|
2811
|
+
h('span', { className: 'dshm-favcard-title dshm-ellipsis' }, tr.title || t('untitled')),
|
|
2812
|
+
h('span', { className: 'dshm-favcard-sub dshm-ellipsis' }, tr.artist || t('unknownArtist')))),
|
|
2813
|
+
h('button', {
|
|
2814
|
+
type: 'button', className: 'dshm-favcard dshm-favcard-more',
|
|
2815
|
+
onClick: () => setLibTab('likes'),
|
|
2816
|
+
},
|
|
2817
|
+
h(IconQueue, { size: 18 }),
|
|
2818
|
+
h('span', { className: 'dshm-favcard-more-label' }, t('favsViewAll')),
|
|
2819
|
+
h('span', { className: 'dshm-count' }, likeItems.length)))),
|
|
2717
2820
|
h('div', { className: 'dshm-toolbar' },
|
|
2718
2821
|
h('label', { className: 'dshm-search' },
|
|
2719
2822
|
h(IconSearch, { size: 15 }),
|
|
@@ -3215,22 +3318,27 @@ window.__ModuleLoader__.load({
|
|
|
3215
3318
|
/* ================================================================
|
|
3216
3319
|
* 11a2. Artist page (V3): profile + songs, play/preview + like
|
|
3217
3320
|
* ================================================================ */
|
|
3218
|
-
function ArtistPageView({ t, reco, player, likes, preview, library, openView, openArtistPage, artistImages, useUi, useLikes, useLibrary, usePlayer, useArtistImages }) {
|
|
3321
|
+
function ArtistPageView({ t, reco, player, likes, preview, library, openView, openArtistPage, artistImages, artistPage, useUi, useLikes, useLibrary, usePlayer, useArtistImages, useArtistPage }) {
|
|
3219
3322
|
const name = useUi((s) => s.artistName);
|
|
3220
3323
|
const tracks = useLibrary((st) => st.tracks);
|
|
3221
3324
|
const currentId = usePlayer((st) => (st.track ? st.track.id : null));
|
|
3222
3325
|
const playing = usePlayer((st) => st.playing);
|
|
3223
|
-
|
|
3326
|
+
/* Loading lives in the shared session-cache service, not in this view:
|
|
3327
|
+
* navigating away does not abort it, reopening the same artist is instant,
|
|
3328
|
+
* and the panel toasts when a background load finishes. */
|
|
3329
|
+
const pageKey = name ? normalizeZh(name).trim() : '';
|
|
3330
|
+
const cachedPage = useArtistPage ? useArtistPage((snap) => snap.pages[pageKey] || null) : null;
|
|
3331
|
+
const pageBusy = useArtistPage ? useArtistPage((snap) => !!snap.loading[pageKey]) : false;
|
|
3332
|
+
const [pageError, setPageError] = useState('');
|
|
3224
3333
|
const [notice, setNotice] = useState('');
|
|
3225
3334
|
useEffect(() => {
|
|
3226
|
-
if (!name) return undefined;
|
|
3335
|
+
if (!name || cachedPage || !artistPage) return undefined;
|
|
3227
3336
|
let dead = false;
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
.then((data) => { if (!dead) setSt({ status: 'ready', data, error: null }); })
|
|
3231
|
-
.catch((err) => { if (!dead) setSt({ status: 'error', data: null, error: (err && err.message) || String(err) }); });
|
|
3337
|
+
setPageError('');
|
|
3338
|
+
artistPage.load(name).catch((err) => { if (!dead) setPageError((err && err.message) || String(err)); });
|
|
3232
3339
|
return () => { dead = true; };
|
|
3233
|
-
}, [name]);
|
|
3340
|
+
}, [name, cachedPage]);
|
|
3341
|
+
const st = { status: cachedPage ? 'ready' : (pageError ? 'error' : 'loading'), data: cachedPage, error: pageError };
|
|
3234
3342
|
function onPlaySong(item) {
|
|
3235
3343
|
playSong(item, player, tracks, preview, setNotice, t);
|
|
3236
3344
|
}
|
|
@@ -3612,7 +3720,7 @@ window.__ModuleLoader__.load({
|
|
|
3612
3720
|
/* ================================================================
|
|
3613
3721
|
* 12. Music panel (main slot): header + tabs + per-view body
|
|
3614
3722
|
* ================================================================ */
|
|
3615
|
-
function MusicPanel({ t, player, library, lyrics, reco, download, sync, history, likes, preview, openView, openArtistPage, setMiniHidden, ui, artistImages, onboarding, useUi, useLibrary, usePlayer, useLyrics, useReco, useDownload, useSync, useHistory, useLikes, usePreview, useArtistImages, useOnboarding }) {
|
|
3723
|
+
function MusicPanel({ t, player, library, lyrics, reco, download, sync, history, likes, preview, openView, openArtistPage, setMiniHidden, ui, artistImages, artistPage, onboarding, useUi, useLibrary, usePlayer, useLyrics, useReco, useDownload, useSync, useHistory, useLikes, usePreview, useArtistImages, useArtistPage, useOnboarding }) {
|
|
3616
3724
|
const view = useUi((s) => s.view);
|
|
3617
3725
|
const welcomePreview = useUi((s) => s.welcomePreview);
|
|
3618
3726
|
const onboardingSnap = useOnboarding((st) => st);
|
|
@@ -3623,6 +3731,24 @@ window.__ModuleLoader__.load({
|
|
|
3623
3731
|
const playing = usePlayer((s) => s.playing);
|
|
3624
3732
|
const busy = status === 'loading';
|
|
3625
3733
|
|
|
3734
|
+
/* Background loads (v9): when an artist page finishes while the user is
|
|
3735
|
+
* looking at another view, surface a toast that jumps straight there. */
|
|
3736
|
+
const pageReady = useArtistPage ? useArtistPage((snap) => snap.lastReady) : null;
|
|
3737
|
+
const toast = useUi((s) => s.toast);
|
|
3738
|
+
const [seenReadyAt, setSeenReadyAt] = useState(0);
|
|
3739
|
+
useEffect(() => {
|
|
3740
|
+
if (!pageReady || pageReady.at === seenReadyAt) return;
|
|
3741
|
+
setSeenReadyAt(pageReady.at);
|
|
3742
|
+
const cur = ui.getSnapshot();
|
|
3743
|
+
if (cur.view === 'artist' && normalizeZh(cur.artistName || '').trim() === pageReady.key) return;
|
|
3744
|
+
ui.set({ toast: { kind: 'artist', name: pageReady.name, at: pageReady.at } });
|
|
3745
|
+
}, [pageReady]);
|
|
3746
|
+
useEffect(() => {
|
|
3747
|
+
if (!toast) return undefined;
|
|
3748
|
+
const timer = setTimeout(() => ui.set({ toast: null }), 9000);
|
|
3749
|
+
return () => clearTimeout(timer);
|
|
3750
|
+
}, [toast]);
|
|
3751
|
+
|
|
3626
3752
|
if (view === 'welcome') {
|
|
3627
3753
|
return h(WelcomeView, {
|
|
3628
3754
|
t, onboarding, useOnboarding,
|
|
@@ -3651,7 +3777,7 @@ window.__ModuleLoader__.load({
|
|
|
3651
3777
|
: view === 'reco'
|
|
3652
3778
|
? h(RecoView, { t, reco, download, player, library, likes, preview, history, openArtistPage, useReco, useDownload, useLibrary, useLikes, usePlayer, useHistory })
|
|
3653
3779
|
: view === 'artist'
|
|
3654
|
-
? h(ArtistPageView, { t, reco, player, likes, preview, library, openView, openArtistPage, artistImages, useUi, useLikes, useLibrary, usePlayer, useArtistImages })
|
|
3780
|
+
? h(ArtistPageView, { t, reco, player, likes, preview, library, openView, openArtistPage, artistImages, artistPage, useUi, useLikes, useLibrary, usePlayer, useArtistImages, useArtistPage })
|
|
3655
3781
|
: view === 'history'
|
|
3656
3782
|
? h(HistoryView, { t, history, player, openArtistPage, artistImages, likes, useHistory, useLibrary, useArtistImages, useLikes })
|
|
3657
3783
|
: h(NowPlayingView, { t, player, lyrics, usePlayer, useLyrics, openView, openArtistPage, artistImages, useArtistImages });
|
|
@@ -3685,7 +3811,20 @@ window.__ModuleLoader__.load({
|
|
|
3685
3811
|
className: 'dshm-tab', 'aria-selected': view === tab.id,
|
|
3686
3812
|
onClick: () => openView(tab.id),
|
|
3687
3813
|
}, tab.label, tab.dot ? h('span', { className: 'dshm-tab-dot', 'aria-hidden': true }) : null)))),
|
|
3688
|
-
h('div', { className: 'dshm-body', role: 'tabpanel' }, body))
|
|
3814
|
+
h('div', { className: 'dshm-body', role: 'tabpanel' }, body)),
|
|
3815
|
+
toast
|
|
3816
|
+
? h('div', { className: 'dshm-toast', role: 'status' },
|
|
3817
|
+
h('span', { className: 'dshm-toast-icon' }, h(IconCheck, { size: 14 })),
|
|
3818
|
+
h('button', {
|
|
3819
|
+
type: 'button', className: 'dshm-toast-main',
|
|
3820
|
+
onClick: () => { ui.set({ toast: null }); openArtistPage(toast.name); },
|
|
3821
|
+
},
|
|
3822
|
+
toast.kind === 'artist' ? t('artistReadyToast') + ' · ' + toast.name : t('pageReadyToast')),
|
|
3823
|
+
h('button', {
|
|
3824
|
+
type: 'button', className: 'dshm-toast-x', 'aria-label': t('closeNotice'),
|
|
3825
|
+
onClick: () => ui.set({ toast: null }),
|
|
3826
|
+
}, h(IconClose, { size: 12 })))
|
|
3827
|
+
: null);
|
|
3689
3828
|
}
|
|
3690
3829
|
|
|
3691
3830
|
/* ================================================================
|
|
@@ -3938,6 +4077,7 @@ window.__ModuleLoader__.load({
|
|
|
3938
4077
|
const library = createLibrary(api);
|
|
3939
4078
|
const lyricsService = createLyricsService(api);
|
|
3940
4079
|
const artistService = createArtistService(api);
|
|
4080
|
+
const artistPageService = createArtistPageService(api);
|
|
3941
4081
|
const artistImageService = createArtistImageService(api);
|
|
3942
4082
|
const onboardingService = createOnboardingService(api);
|
|
3943
4083
|
const recoService = createRecoService(api);
|
|
@@ -4014,10 +4154,10 @@ window.__ModuleLoader__.load({
|
|
|
4014
4154
|
player, library, lyrics: lyricsService, artist: artistService, artistImages: artistImageService, onboarding: onboardingService,
|
|
4015
4155
|
reco: recoService, download: downloadService, sync: syncService, history: historyService,
|
|
4016
4156
|
likes: likesService, preview: previewService,
|
|
4017
|
-
openView, openArtistPage, setMiniHidden, ui,
|
|
4157
|
+
openView, openArtistPage, setMiniHidden, ui, artistPage: artistPageService,
|
|
4018
4158
|
hooks: {
|
|
4019
4159
|
player: player.source, library: library.source, ui,
|
|
4020
|
-
lyrics: lyricsService.source, artist: artistService.source, artistImages: artistImageService.source, onboarding: onboardingService.source,
|
|
4160
|
+
lyrics: lyricsService.source, artist: artistService.source, artistPage: artistPageService.source, artistImages: artistImageService.source, onboarding: onboardingService.source,
|
|
4021
4161
|
reco: recoService.source, download: downloadService.source,
|
|
4022
4162
|
sync: syncService.source, history: historyService.source,
|
|
4023
4163
|
likes: likesService.source, preview: previewService.source,
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/host/metadata/artist.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { slugify } from './cache.js'
|
|
4
4
|
|
|
5
5
|
const UA = 'dsh-music/0.1 (local music plugin; artist content)'
|
|
6
|
+
/** 九期点4:简介/资料缓存 TTL 30 天(Chief 建议 7–30 天取上限),过期后下次打开刷新。 */
|
|
7
|
+
const PROFILE_TTL_MS = 30 * 24 * 3600 * 1000
|
|
6
8
|
|
|
7
9
|
function today() {
|
|
8
10
|
return new Date().toISOString().slice(0, 10)
|
|
@@ -50,7 +52,8 @@ export function createArtistContent({ cache, logger }) {
|
|
|
50
52
|
async get(name) {
|
|
51
53
|
const slug = slugify(name)
|
|
52
54
|
const hit = await cache.readJson(cache.artistFile(slug))
|
|
53
|
-
|
|
55
|
+
const fresh = hit && hit.version === 1 && hit.data && Date.now() - (hit.fetchedAt ?? 0) < PROFILE_TTL_MS
|
|
56
|
+
if (fresh) {
|
|
54
57
|
const d = hit.data
|
|
55
58
|
return {
|
|
56
59
|
name: d.name ?? name,
|
|
@@ -66,13 +69,30 @@ export function createArtistContent({ cache, logger }) {
|
|
|
66
69
|
}
|
|
67
70
|
const intro = await wikiIntro(name)
|
|
68
71
|
if (intro) {
|
|
72
|
+
// 九期点4:live 兜底成功即持久化(TTL 内重开零网络拉取);写失败只警告不影响返回。
|
|
73
|
+
// 过期刷新时合并保留原有调研字段(news/trivia/similar 不被空数组覆盖)。
|
|
74
|
+
const old = hit?.data ?? {}
|
|
75
|
+
const keep = (cur, prev) => (Array.isArray(cur) && cur.length > 0 ? cur : Array.isArray(prev) ? prev : [])
|
|
76
|
+
const data = {
|
|
77
|
+
name,
|
|
78
|
+
intro,
|
|
79
|
+
news: keep([], old.news),
|
|
80
|
+
trivia: keep([], old.trivia),
|
|
81
|
+
similarArtists: keep([], old.similarArtists),
|
|
82
|
+
similarSongs: keep([], old.similarSongs),
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
await cache.writeJson(cache.artistFile(slug), { version: 1, data, fetchedAt: Date.now() })
|
|
86
|
+
} catch (err) {
|
|
87
|
+
warn(`dsh-music: 回写歌手缓存失败 ${name}: ${err.message}`)
|
|
88
|
+
}
|
|
69
89
|
return {
|
|
70
90
|
name,
|
|
71
91
|
intro,
|
|
72
|
-
news:
|
|
73
|
-
trivia:
|
|
74
|
-
similarArtists:
|
|
75
|
-
similarSongs:
|
|
92
|
+
news: data.news,
|
|
93
|
+
trivia: data.trivia,
|
|
94
|
+
similarArtists: data.similarArtists,
|
|
95
|
+
similarSongs: data.similarSongs,
|
|
76
96
|
cached: false,
|
|
77
97
|
fetchedAt: Date.now(),
|
|
78
98
|
message: '动态/逸闻/相似内容由调研补齐',
|
package/host/reco/index.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* const reco = createReco({ history, library, storage, config, logger })
|
|
11
11
|
* ctx.effect 内:...registerRecoRoutes(ctx.webServer, { reco, logger });清理 reco.dispose()
|
|
12
12
|
* 打包:package.json files 需含 host/reco 下全部 js(host 双星 glob 已覆盖)。 */
|
|
13
|
-
import { join } from 'node:path'
|
|
14
|
-
import { readFile, writeFile, rename } from 'node:fs/promises'
|
|
13
|
+
import { join, dirname } from 'node:path'
|
|
14
|
+
import { readFile, writeFile, rename, mkdir } from 'node:fs/promises'
|
|
15
15
|
import { createVerifier } from './verify.js'
|
|
16
16
|
import { createDiscover } from './discover.js'
|
|
17
17
|
import { detectLanguage } from './diversity.js'
|
|
@@ -46,6 +46,7 @@ export function createReco({ history, library, storage, config = {}, logger, ver
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
async function writeJson(file, value) {
|
|
49
|
+
await mkdir(dirname(file), { recursive: true })
|
|
49
50
|
const tmp = `${file}.tmp-${process.pid}`
|
|
50
51
|
await writeFile(tmp, JSON.stringify(value), 'utf8')
|
|
51
52
|
await rename(tmp, file)
|
|
@@ -303,8 +304,20 @@ export function createReco({ history, library, storage, config = {}, logger, ver
|
|
|
303
304
|
let profile = cached?.data ?? null
|
|
304
305
|
let message = null
|
|
305
306
|
if (!profile) {
|
|
306
|
-
|
|
307
|
-
if (
|
|
307
|
+
const live = await liveWikiProfile(a.name)
|
|
308
|
+
if (live) {
|
|
309
|
+
// 九期点4:live 维基兜底成功即持久化(与 metadata/artist.js 同一缓存格式/路径,两条路径共享,
|
|
310
|
+
// TTL 内重开零网络拉取);写失败只告警,不影响本次返回。
|
|
311
|
+
const data = { name: a.name, ...live }
|
|
312
|
+
try {
|
|
313
|
+
await writeJson(cacheFile, { version: 1, data, fetchedAt: Date.now() })
|
|
314
|
+
} catch (err) {
|
|
315
|
+
warn?.(`dsh-music: 回写歌手缓存失败 ${a.name}: ${err.message}`)
|
|
316
|
+
}
|
|
317
|
+
profile = data
|
|
318
|
+
} else {
|
|
319
|
+
message = '暂无该歌手资料'
|
|
320
|
+
}
|
|
308
321
|
}
|
|
309
322
|
if (typeof library.ensureScanned === 'function') await library.ensureScanned()
|
|
310
323
|
const tracks = library.snapshot()?.tracks ?? []
|
package/host/reco/verify.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createHash } from 'node:crypto'
|
|
|
7
7
|
import { mbJson, mbUrl } from './mb.js'
|
|
8
8
|
|
|
9
9
|
const CACHE_TTL_MS = 30 * 24 * 3600 * 1000
|
|
10
|
+
const NEG_TTL_MS = 3 * 24 * 3600 * 1000 // 未命中负缓存 3 天(与 images.js 无图负缓存一致)
|
|
10
11
|
|
|
11
12
|
function norm(s) {
|
|
12
13
|
return String(s ?? '').toLowerCase().replace(/[\s'"’·・\-—–,,.。!!??::;;()()\[\]【】]/g, '')
|
|
@@ -28,6 +29,26 @@ export function createVerifier({ storage, logger } = {}) {
|
|
|
28
29
|
return null
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
/** 未命中负缓存:只挡重查,绝不构成「核实通过」——下载前仍以 verify 返回记录为准。 */
|
|
33
|
+
async function readNegative(key) {
|
|
34
|
+
try {
|
|
35
|
+
const saved = JSON.parse(await readFile(join(dir, `${key}.json`), 'utf8'))
|
|
36
|
+
if (saved?.miss === true && Number.isFinite(saved.missedAt) && Date.now() - saved.missedAt < NEG_TTL_MS) return true
|
|
37
|
+
} catch { /* 无缓存 */ }
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function writeNegative(key, artist, title) {
|
|
42
|
+
try {
|
|
43
|
+
await mkdir(dir, { recursive: true })
|
|
44
|
+
const tmp = join(dir, `${key}.tmp-${process.pid}`)
|
|
45
|
+
await writeFile(tmp, JSON.stringify({ miss: true, missedAt: Date.now(), artist, title }), 'utf8')
|
|
46
|
+
await rename(tmp, join(dir, `${key}.json`))
|
|
47
|
+
} catch (err) {
|
|
48
|
+
warn?.(`dsh-music: 写核实负缓存失败: ${err.message}`)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
31
52
|
async function writeCache(key, record) {
|
|
32
53
|
try {
|
|
33
54
|
await mkdir(dir, { recursive: true })
|
|
@@ -62,6 +83,7 @@ export function createVerifier({ storage, logger } = {}) {
|
|
|
62
83
|
const key = cacheKey(artist, title)
|
|
63
84
|
const cached = await readCache(key)
|
|
64
85
|
if (cached) return cached
|
|
86
|
+
if (await readNegative(key)) return null // 3 天内已确认未命中,不重复打 MusicBrainz
|
|
65
87
|
|
|
66
88
|
const query = `artist:"${artist}" AND recording:"${title}"`
|
|
67
89
|
const url = mbUrl('recording', { query, limit: 8 })
|
|
@@ -76,7 +98,10 @@ export function createVerifier({ storage, logger } = {}) {
|
|
|
76
98
|
const target = Number(durationMs) > 0 ? Number(durationMs) : null
|
|
77
99
|
const recordings = Array.isArray(data?.recordings) ? data.recordings : []
|
|
78
100
|
const hits = recordings.filter((r) => artistMatches(r['artist-credit'] ?? [], artist) && titleMatches(r.title, title))
|
|
79
|
-
if (hits.length === 0)
|
|
101
|
+
if (hits.length === 0) {
|
|
102
|
+
await writeNegative(key, artist, title) // 网络失败不落负缓存(仅确定性未命中)
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
80
105
|
let best = hits[0]
|
|
81
106
|
if (target !== null) {
|
|
82
107
|
const withDur = hits.filter((r) => Number.isFinite(r.length))
|