feat: backend integration of playlist m3u text
This commit is contained in:
@@ -30,11 +30,10 @@ class ChannelService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addChannel({ name, url, avatar, mode, headersJson, group = null, playlist = null, playlistName = null }) {
|
addChannel({ name, url, avatar, mode, headersJson, group = null, playlist = null, playlistName = null }) {
|
||||||
const existing = this.channels.find(channel => channel.url === url);
|
// const existing = this.channels.find(channel => channel.url === url);
|
||||||
|
// if (existing) {
|
||||||
if (existing) {
|
// throw new Error('Channel already exists');
|
||||||
throw new Error('Channel already exists');
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
const headers = JSON.parse(headersJson);
|
const headers = JSON.parse(headersJson);
|
||||||
const newChannel = new Channel(name, url, avatar, mode, headers, group, playlist, playlistName);
|
const newChannel = new Channel(name, url, avatar, mode, headers, group, playlist, playlistName);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ module.exports = {
|
|||||||
return channelsJson.map(channelJson => Channel.from(channelJson));
|
return channelsJson.map(channelJson => Channel.from(channelJson));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error loading data from storage:', err);
|
console.error('Error loading data from storage:', err);
|
||||||
return [];
|
return channels;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.save(channels);
|
this.save(channels);
|
||||||
|
|||||||
@@ -3,12 +3,17 @@ const ChannelService = require('./ChannelService');
|
|||||||
|
|
||||||
class PlaylistService {
|
class PlaylistService {
|
||||||
|
|
||||||
async addPlaylist(playlistUrl, playlistName, mode, headersJson) {
|
async addPlaylist(playlist, playlistName, mode, headersJson) {
|
||||||
|
|
||||||
console.log('Adding playlist', playlistUrl);
|
console.log('Adding playlist', playlist);
|
||||||
|
|
||||||
const response = await fetch(playlistUrl);
|
let content = "";
|
||||||
const content = await response.text();
|
if(playlist.startsWith("http")) {
|
||||||
|
const response = await fetch(playlist);
|
||||||
|
content = await response.text();
|
||||||
|
} else {
|
||||||
|
content = playlist;
|
||||||
|
}
|
||||||
|
|
||||||
const parsedPlaylist = m3uParser.parse(content);
|
const parsedPlaylist = m3uParser.parse(content);
|
||||||
|
|
||||||
@@ -23,7 +28,7 @@ class PlaylistService {
|
|||||||
mode: mode,
|
mode: mode,
|
||||||
headersJson: headersJson,
|
headersJson: headersJson,
|
||||||
group: channel.group.title,
|
group: channel.group.title,
|
||||||
playlist: playlistUrl,
|
playlist: playlist,
|
||||||
playlistName: playlistName
|
playlistName: playlistName
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -36,9 +36,19 @@ function ChannelModal({ onClose, channel }: ChannelModalProps) {
|
|||||||
setMode(channel.mode);
|
setMode(channel.mode);
|
||||||
setHeaders(channel.headers);
|
setHeaders(channel.headers);
|
||||||
setPlaylistName(channel.playlistName);
|
setPlaylistName(channel.playlistName);
|
||||||
setPlaylistUrl(channel.playlist);
|
|
||||||
setIsEditMode(true);
|
setIsEditMode(true);
|
||||||
setType('channel');
|
setType('channel');
|
||||||
|
|
||||||
|
if(channel.playlist.startsWith("http")) {
|
||||||
|
setInputMethod('url');
|
||||||
|
setPlaylistUrl(channel.playlist);
|
||||||
|
setPlaylistText('');
|
||||||
|
} else {
|
||||||
|
setInputMethod('text');
|
||||||
|
setPlaylistUrl('');
|
||||||
|
setPlaylistText(channel.playlist);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
setName('');
|
setName('');
|
||||||
setUrl('');
|
setUrl('');
|
||||||
@@ -50,6 +60,7 @@ function ChannelModal({ onClose, channel }: ChannelModalProps) {
|
|||||||
setPlaylistText('');
|
setPlaylistText('');
|
||||||
setIsEditMode(false);
|
setIsEditMode(false);
|
||||||
setType('channel');
|
setType('channel');
|
||||||
|
setInputMethod('url');
|
||||||
}
|
}
|
||||||
}, [channel]);
|
}, [channel]);
|
||||||
|
|
||||||
@@ -92,8 +103,7 @@ function ChannelModal({ onClose, channel }: ChannelModalProps) {
|
|||||||
inputMethod === 'url' ? playlistUrl.trim() : playlistText.trim(),
|
inputMethod === 'url' ? playlistUrl.trim() : playlistText.trim(),
|
||||||
playlistName.trim(),
|
playlistName.trim(),
|
||||||
mode,
|
mode,
|
||||||
JSON.stringify(headers),
|
JSON.stringify(headers)
|
||||||
inputMethod === 'text'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,18 +126,17 @@ function ChannelModal({ onClose, channel }: ChannelModalProps) {
|
|||||||
headers: headers,
|
headers: headers,
|
||||||
});
|
});
|
||||||
} else if (type === 'playlist') {
|
} else if (type === 'playlist') {
|
||||||
if(channel!.playlist !== playlistUrl.trim()) {
|
const newPlaylist = inputMethod === 'url' ? playlistUrl.trim() : playlistText.trim();
|
||||||
|
if(channel!.playlist !== newPlaylist) {
|
||||||
socketService.deletePlaylist(channel!.playlist);
|
socketService.deletePlaylist(channel!.playlist);
|
||||||
socketService.addPlaylist(
|
socketService.addPlaylist(
|
||||||
inputMethod === 'url' ? playlistUrl.trim() : playlistText.trim(),
|
inputMethod === 'url' ? playlistUrl.trim() : playlistText.trim(),
|
||||||
playlistName.trim(),
|
playlistName.trim(),
|
||||||
mode,
|
mode,
|
||||||
JSON.stringify(headers),
|
JSON.stringify(headers)
|
||||||
inputMethod === 'text'
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
socketService.updatePlaylist(playlistUrl.trim(), {
|
socketService.updatePlaylist(channel!.playlist, {
|
||||||
playlist: playlistUrl.trim(),
|
|
||||||
playlistName: playlistName.trim(),
|
playlistName: playlistName.trim(),
|
||||||
mode: mode,
|
mode: mode,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
|
|||||||
Reference in New Issue
Block a user