@doitian/dsh-music 1.0.0 → 1.2.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/lib/index.js CHANGED
@@ -33,7 +33,7 @@ export const inject = ['tools', 'webServer'];
33
33
 
34
34
  const HERE = path.dirname(fileURLToPath(import.meta.url));
35
35
 
36
- /** Read a shipped asset once at module load; both are small. */
36
+ /** Read a shipped asset once at module load; they are small. */
37
37
  function readAsset(...segments) {
38
38
  return fs.readFileSync(path.join(HERE, ...segments), 'utf8');
39
39
  }
@@ -44,9 +44,12 @@ function readAsset(...segments) {
44
44
  * Deliberately module-scoped rather than read inside {@link apply}: a plugin
45
45
  * remount re-runs `apply`, and reading here instead would let a remounted
46
46
  * plugin serve a page from a *newer* working tree than the code it is running
47
- * beside. The page and the module must describe the same contract.
47
+ * beside. The page and the module must describe the same contract, and so must
48
+ * the playback core: the page runs it, and the engine trusts it on the strength
49
+ * of that contract.
48
50
  */
49
51
  const PANEL_HTML = readAsset('panel.html');
52
+ const PLAYBACK_JS = readAsset('playback.js');
50
53
  const QRCODE_JS = readAsset('vendor', 'qrcode.js');
51
54
 
52
55
  /**
@@ -279,6 +282,7 @@ export function apply(ctx, config = {}) {
279
282
  likes,
280
283
  scrobbler,
281
284
  panelHtml: PANEL_HTML,
285
+ playbackJs: PLAYBACK_JS,
282
286
  qrcodeJs: QRCODE_JS,
283
287
  config,
284
288
  listRoutes: () => dj.listRoutes(),
@@ -752,6 +756,7 @@ export function apply(ctx, config = {}) {
752
756
  } catch {
753
757
  // The route table is already gone when the webserver unloads first.
754
758
  }
759
+ router.dispose();
755
760
  store.close();
756
761
  logger.debug('[music] unloaded');
757
762
  });
package/lib/netease.js CHANGED
@@ -529,11 +529,22 @@ export class Netease {
529
529
  return data?.data?.[0];
530
530
  }
531
531
 
532
- /** Synced lyric text. `noLyric: true` marks an instrumental. */
532
+ /**
533
+ * Synced lyric text. `noLyric: true` marks an instrumental.
534
+ *
535
+ * A refusal (rate limiting, a risk check) carries no lyric either, so it
536
+ * throws rather than reading as an instrumental the caches would keep.
537
+ */
533
538
  async lyric(id) {
534
539
  const data = await this.call('/api/song/lyric', {
535
540
  query: { id: Number(id), lv: 1, kv: 1, tv: -1 },
536
541
  });
542
+ if (data?.code !== 200) {
543
+ throw new NeteaseError(data?.message || `lyrics refused (code ${data?.code})`, {
544
+ code: data?.code,
545
+ endpoint: 'song/lyric',
546
+ });
547
+ }
537
548
  return {
538
549
  lrc: data?.lrc?.lyric ?? '',
539
550
  translated: data?.tlyric?.lyric ?? '',