From 96fabac7f5d72b77d22f14e749834a4b5cb20388 Mon Sep 17 00:00:00 2001 From: nk Date: Wed, 3 Jun 2026 14:20:41 +0300 Subject: [PATCH] =?UTF-8?q?fix(now-playing):=20=D1=80=D0=B5=D0=B7=D0=BE?= =?UTF-8?q?=D0=BB=D0=B2=D0=B8=D1=82=D1=8C=20=D0=BE=D0=B1=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=BA=D1=83=20=D1=82=D1=80=D0=B5=D0=BA=D0=B0=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D0=B8=20/now-playing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Обложка ICY-станций (DFM) теперь подтягивается из обогащённого трека по normKey в момент ответа API, а не записи now_playing — появляется сразу после обогащения, без ожидания следующего опроса станции (~6 мин). Co-Authored-By: Claude Opus 4.8 --- src/now-playing/now-playing.service.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/now-playing/now-playing.service.ts b/src/now-playing/now-playing.service.ts index 7ebe39d..e30a99c 100644 --- a/src/now-playing/now-playing.service.ts +++ b/src/now-playing/now-playing.service.ts @@ -197,8 +197,31 @@ export class NowPlayingService { } async getAllNowPlaying() { - return this.prisma.nowPlaying.findMany({ + const list = await this.prisma.nowPlaying.findMany({ include: { station: true }, }); + + // Для записей без своей обложки (ICY-станции типа DFM) подтягиваем обложку + // обогащённого трека из нашей БД по normKey — на чтении, чтобы она появлялась + // сразу после обогащения, не дожидаясь следующего опроса станции. + const missing = list.filter((np) => !np.coverUrl && np.artist && np.song); + if (missing.length > 0) { + const keys = [ + ...new Set(missing.map((np) => this.buildNormKey(np.artist, np.song))), + ]; + const tracks = await this.prisma.track.findMany({ + where: { normKey: { in: keys }, coverUrl: { not: null } }, + select: { normKey: true, coverUrl: true }, + }); + const coverByKey = new Map(tracks.map((t) => [t.normKey, t.coverUrl])); + for (const np of list) { + if (!np.coverUrl && np.artist && np.song) { + const cover = coverByKey.get(this.buildNormKey(np.artist, np.song)); + if (cover) np.coverUrl = cover; + } + } + } + + return list; } }