feat: add clear channels api endpoint
This commit is contained in:
@@ -53,4 +53,9 @@ module.exports = {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
},
|
||||
|
||||
clearChannels(req, res) {
|
||||
ChannelService.clearChannels();
|
||||
res.status(204).send();
|
||||
}
|
||||
};
|
||||
@@ -21,6 +21,7 @@ app.use(express.json());
|
||||
const apiRouter = express.Router();
|
||||
apiRouter.get('/', channelController.getChannels);
|
||||
apiRouter.get('/current', channelController.getCurrentChannel);
|
||||
apiRouter.delete('/clear', channelController.clearChannels);
|
||||
apiRouter.get('/playlist', centralChannelController.playlist);
|
||||
apiRouter.get('/:channelId', channelController.getChannel);
|
||||
apiRouter.delete('/:channelId', channelController.deleteChannel);
|
||||
|
||||
@@ -10,6 +10,12 @@ class ChannelService {
|
||||
this.currentChannel = this.channels[0];
|
||||
}
|
||||
|
||||
clearChannels() {
|
||||
ChannelStorage.clear();
|
||||
this.channels = ChannelStorage.load();
|
||||
this.currentChannel = this.channels[0];
|
||||
}
|
||||
|
||||
getChannels() {
|
||||
return this.channels;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Channel = require('../models/Channel');
|
||||
const { clear } = require('console');
|
||||
|
||||
const storageFilePath = path.resolve('/channels/channels.json');
|
||||
|
||||
@@ -55,5 +56,14 @@ module.exports = {
|
||||
} catch (err) {
|
||||
console.error('Error saving data to storage:', err);
|
||||
}
|
||||
},
|
||||
|
||||
clear() {
|
||||
try {
|
||||
fs.unlinkSync(storageFilePath);
|
||||
console.log('Data cleared successfully.');
|
||||
} catch (err) {
|
||||
console.error('Error clearing data from storage:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,9 @@ class PlaylistService {
|
||||
}
|
||||
} else {
|
||||
content = playlist;
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync(`/channels/${playlistName}.txt`, playlist, { encoding: 'utf-8' }, (err) => err && console.error(err));
|
||||
console.log('Adding playlist to playlist.m3u8');
|
||||
}
|
||||
|
||||
const parsedPlaylist = m3uParser.parse(content);
|
||||
|
||||
@@ -56,6 +56,7 @@ class PlaylistUpdater {
|
||||
try {
|
||||
// Fetch and renew playlist
|
||||
await PlaylistService.deletePlaylist(playlist.playlist);
|
||||
console.log('Adding playlist with playlistUpdate:', playlist.playlistUpdate);
|
||||
await PlaylistService.addPlaylist(
|
||||
playlist.playlist,
|
||||
playlist.playlistName,
|
||||
|
||||
@@ -4,6 +4,7 @@ module.exports = (io, socket) => {
|
||||
|
||||
socket.on('add-channel', ({ name, url, avatar, mode, headersJson }) => {
|
||||
try {
|
||||
console.log('Adding solo channel:', url);
|
||||
const newChannel = ChannelService.addChannel({ name: name, url: url, avatar: avatar, mode: mode, headersJson: headersJson });
|
||||
io.emit('channel-added', newChannel); // Broadcast to all clients
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user