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