Added backend functionality for channel playlist deletion
This commit is contained in:
parent
37f7f21c5a
commit
65b5ae9371
|
|
@ -35,6 +35,7 @@ module.exports = class{
|
||||||
//socket.on("queue", (data) => {this.queueURL(socket, data)});
|
//socket.on("queue", (data) => {this.queueURL(socket, data)});
|
||||||
socket.on("getChannelPlaylists", () => {this.getChannelPlaylists(socket)});
|
socket.on("getChannelPlaylists", () => {this.getChannelPlaylists(socket)});
|
||||||
socket.on("createChannelPlaylist", (data) => {this.createChannelPlaylist(socket, data)});
|
socket.on("createChannelPlaylist", (data) => {this.createChannelPlaylist(socket, data)});
|
||||||
|
socket.on("deleteChannelPlaylist", (data) => {this.deleteChannelPlaylist(socket, data)});
|
||||||
socket.on("addToChannelPlaylist", (data) => {this.addToChannelPlaylist(socket, data)});
|
socket.on("addToChannelPlaylist", (data) => {this.addToChannelPlaylist(socket, data)});
|
||||||
socket.on("queueChannelPlaylist", (data) => {this.queueChannelPlaylist(socket, data)});
|
socket.on("queueChannelPlaylist", (data) => {this.queueChannelPlaylist(socket, data)});
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +61,7 @@ module.exports = class{
|
||||||
|
|
||||||
//Add playlist to the channel doc
|
//Add playlist to the channel doc
|
||||||
chanDB.media.playlists.push({
|
chanDB.media.playlists.push({
|
||||||
name: data.name,
|
name: data.playlist,
|
||||||
defaultTitles: data.defaultTitles
|
defaultTitles: data.defaultTitles
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -71,6 +72,20 @@ module.exports = class{
|
||||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deleteChannelPlaylist(socket, data, chanDB){
|
||||||
|
//if we wherent handed a channel document
|
||||||
|
if(chanDB == null){
|
||||||
|
//Pull it based on channel name
|
||||||
|
chanDB = await channelModel.findOne({name: this.channel.name});
|
||||||
|
}
|
||||||
|
|
||||||
|
//Delete playlist name
|
||||||
|
await chanDB.deletePlaylistByName(data.playlist);
|
||||||
|
|
||||||
|
//Return playlists from channel doc
|
||||||
|
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||||
|
}
|
||||||
|
|
||||||
async addToChannelPlaylist(socket, data, chanDB){
|
async addToChannelPlaylist(socket, data, chanDB){
|
||||||
//if we wherent handed a channel document
|
//if we wherent handed a channel document
|
||||||
if(chanDB == null){
|
if(chanDB == null){
|
||||||
|
|
|
||||||
|
|
@ -596,6 +596,26 @@ channelSchema.methods.getPlaylistByName = function(name){
|
||||||
return foundPlaylist;
|
return foundPlaylist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
channelSchema.methods.deletePlaylistByName = async function(name){
|
||||||
|
//Create null value to hold our found playlist
|
||||||
|
let foundIndex = null;
|
||||||
|
|
||||||
|
//Crawl through active playlists
|
||||||
|
this.playlistCrawl((playlist, listIndex) => {
|
||||||
|
//If we found a match based on name
|
||||||
|
if(playlist.name == name){
|
||||||
|
//Yoink it's index
|
||||||
|
foundIndex = listIndex;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//splice out the given playlist
|
||||||
|
this.media.playlists.splice(foundIndex, 1);
|
||||||
|
|
||||||
|
//save the channel document
|
||||||
|
await this.save();
|
||||||
|
}
|
||||||
|
|
||||||
channelSchema.methods.addToPlaylist = async function(name, media){
|
channelSchema.methods.addToPlaylist = async function(name, media){
|
||||||
//Create variable to hold found index
|
//Create variable to hold found index
|
||||||
let foundIndex = null
|
let foundIndex = null
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue