feat: improve channel deletion logic

This commit is contained in:
antebrl
2025-11-13 18:28:52 +01:00
parent 62a3b506b5
commit 4a55c4575e
3 changed files with 16 additions and 8 deletions

View File

@@ -62,8 +62,9 @@ app.use('/proxy', proxyRouter);
const PORT = 5000;
const server = app.listen(PORT, async () => {
console.log(`Server listening on Port ${PORT}`);
if (ChannelService.getCurrentChannel().restream()) {
await streamController.start(ChannelService.getCurrentChannel());
const currentChannel = ChannelService.getCurrentChannel();
if (currentChannel && currentChannel.restream()) {
await streamController.start(currentChannel);
}
PlaylistUpdater.startScheduler();
PlaylistUpdater.registerChannelsPlaylist(ChannelService.getChannels());

View File

@@ -88,10 +88,17 @@ class ChannelService {
throw new Error('Channel does not exist');
}
// Prevent deleting the last channel
if (this.channels.length === 1) {
throw new Error('Cannot delete the last channel');
}
const [deletedChannel] = this.channels.splice(channelIndex, 1);
// If we deleted the current channel, switch to another one
if (this.currentChannel.id === id) {
await this.setCurrentChannel(0);
const nextChannel = this.channels[0];
await this.setCurrentChannel(nextChannel.id);
}
if(save) ChannelStorage.save(this.channels);