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; } }