fix: broadcast stationId as int for Android mapping
This commit is contained in:
@@ -50,16 +50,15 @@ export class NowPlayingService {
|
||||
let updatedCount = 0;
|
||||
|
||||
for (const np of nowPlaying) {
|
||||
const stationId =
|
||||
this.recordSync.getStationIdByNowPlayingId(np.id);
|
||||
if (!stationId) continue;
|
||||
const mapping = this.recordSync.getStationByNowPlayingId(np.id);
|
||||
if (!mapping) continue;
|
||||
|
||||
const coverUrl = np.track.image600 ?? np.track.image200 ?? np.track.image100;
|
||||
|
||||
const updated = await this.prisma.nowPlaying.upsert({
|
||||
where: { stationId },
|
||||
where: { stationId: mapping.dbId },
|
||||
create: {
|
||||
stationId,
|
||||
stationId: mapping.dbId,
|
||||
song: np.track.song,
|
||||
artist: np.track.artist,
|
||||
coverUrl,
|
||||
@@ -71,7 +70,7 @@ export class NowPlayingService {
|
||||
},
|
||||
});
|
||||
|
||||
this.gateway.broadcastNowPlaying(stationId, {
|
||||
this.gateway.broadcastNowPlaying(mapping.stationId.toString(), {
|
||||
song: np.track.song,
|
||||
artist: np.track.artist,
|
||||
coverUrl,
|
||||
|
||||
@@ -25,10 +25,15 @@ interface RecordNowPlayingItem {
|
||||
track: RecordTrack;
|
||||
}
|
||||
|
||||
export interface StationMapping {
|
||||
dbId: string;
|
||||
stationId: number;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class RecordStationSyncService implements OnModuleInit {
|
||||
private readonly logger = new Logger(RecordStationSyncService.name);
|
||||
private nowPlayingIdToStationId = new Map<number, string>();
|
||||
private nowPlayingIdToStation = new Map<number, StationMapping>();
|
||||
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@@ -78,7 +83,7 @@ export class RecordStationSyncService implements OnModuleInit {
|
||||
|
||||
const ourStations = await this.prisma.station.findMany();
|
||||
let matched = 0;
|
||||
const newMap = new Map<number, string>();
|
||||
const newMap = new Map<number, StationMapping>();
|
||||
|
||||
for (let i = 0; i < recordStations.length; i++) {
|
||||
const rs = recordStations[i];
|
||||
@@ -105,20 +110,20 @@ export class RecordStationSyncService implements OnModuleInit {
|
||||
`https://www.radiorecord.ru/upload/stations_images/${rs.prefix}_image600_colored_fill.png`,
|
||||
},
|
||||
});
|
||||
newMap.set(np.id, match.id);
|
||||
newMap.set(np.id, { dbId: match.id, stationId: match.stationId });
|
||||
matched++;
|
||||
}
|
||||
}
|
||||
|
||||
this.nowPlayingIdToStationId = newMap;
|
||||
this.nowPlayingIdToStation = newMap;
|
||||
this.logger.log(
|
||||
`Matched and updated ${matched} stations, mapped ${newMap.size} now-playing IDs`,
|
||||
);
|
||||
return matched;
|
||||
}
|
||||
|
||||
getStationIdByNowPlayingId(nowPlayingId: number): string | undefined {
|
||||
return this.nowPlayingIdToStationId.get(nowPlayingId);
|
||||
getStationByNowPlayingId(nowPlayingId: number): StationMapping | undefined {
|
||||
return this.nowPlayingIdToStation.get(nowPlayingId);
|
||||
}
|
||||
|
||||
private normalizeStreamUrl(url?: string): string | null {
|
||||
|
||||
Reference in New Issue
Block a user