feat: improve channel deletion logic
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user