Finished up with Playlist Managment UI.
This commit is contained in:
parent
c8c59feb7f
commit
f21b66fae0
7 changed files with 180 additions and 42 deletions
|
|
@ -35,6 +35,7 @@ module.exports = class{
|
|||
socket.on("getChannelPlaylists", () => {this.getChannelPlaylists(socket)});
|
||||
socket.on("createChannelPlaylist", (data) => {this.createChannelPlaylist(socket, data)});
|
||||
socket.on("deleteChannelPlaylist", (data) => {this.deleteChannelPlaylist(socket, data)});
|
||||
socket.on("deleteChannelPlaylistMedia", (data) => {this.deleteChannelPlaylistMedia(socket, data)});
|
||||
socket.on("addToChannelPlaylist", (data) => {this.addToChannelPlaylist(socket, data)});
|
||||
socket.on("queueChannelPlaylist", (data) => {this.queueChannelPlaylist(socket, data)});
|
||||
socket.on("renameChannelPlaylist", (data) => {this.renameChannelPlaylist(socket, data)});
|
||||
|
|
@ -290,4 +291,30 @@ module.exports = class{
|
|||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteChannelPlaylistMedia(socket, data, chanDB){
|
||||
try{
|
||||
//if we wherent handed a channel document
|
||||
if(chanDB == null){
|
||||
//Pull it based on channel name
|
||||
chanDB = await channelModel.findOne({name: this.channel.name});
|
||||
}
|
||||
|
||||
//If we don't have a valid UUID
|
||||
if(!validator.isUUID(data.uuid)){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, `'${data.uuid}' is not a valid UUID!`, "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//Delete media from channel playlist
|
||||
chanDB.deletePlaylistMediaByUUID(data.playlist, data.uuid);
|
||||
|
||||
//Return playlists from channel doc
|
||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -606,6 +606,17 @@ channelSchema.methods.deletePlaylistByName = async function(name){
|
|||
await this.save();
|
||||
}
|
||||
|
||||
channelSchema.methods.deletePlaylistMediaByUUID = async function(name, uuid){
|
||||
//Find the playlist
|
||||
let playlist = this.getPlaylistByName(name);
|
||||
|
||||
//splice out the given playlist
|
||||
this.media.playlists[playlist.listIndex].deleteMedia(uuid);
|
||||
|
||||
//save the channel document
|
||||
await this.save();
|
||||
}
|
||||
|
||||
channelSchema.methods.addToPlaylist = async function(name, media){
|
||||
//Find the playlist
|
||||
let playlist = this.getPlaylistByName(name);
|
||||
|
|
|
|||
|
|
@ -52,4 +52,21 @@ playlistSchema.methods.dehydrate = function(){
|
|||
}
|
||||
}
|
||||
|
||||
playlistSchema.methods.deleteMedia = function(uuid){
|
||||
//Create new array to hold list of media to be kept
|
||||
const keptMedia = [];
|
||||
|
||||
//For every piece of media in the current playlist
|
||||
for(let media of this.media){
|
||||
//It isn't the media to be deleted
|
||||
if(media.uuid.toString() != uuid){
|
||||
//Add it to the list to be kept
|
||||
keptMedia.push(media);
|
||||
}
|
||||
}
|
||||
|
||||
//Set playlist media from keptMedia
|
||||
this.media = keptMedia;
|
||||
}
|
||||
|
||||
module.exports = playlistSchema;
|
||||
Loading…
Add table
Add a link
Reference in a new issue