Continued work on playlist management UI
This commit is contained in:
parent
04dec153ac
commit
c3781d6259
7 changed files with 201 additions and 32 deletions
|
|
@ -38,6 +38,7 @@ module.exports = class{
|
|||
socket.on("addToChannelPlaylist", (data) => {this.addToChannelPlaylist(socket, data)});
|
||||
socket.on("queueChannelPlaylist", (data) => {this.queueChannelPlaylist(socket, data)});
|
||||
socket.on("renameChannelPlaylist", (data) => {this.renameChannelPlaylist(socket, data)});
|
||||
socket.on("changeDefaultTitlesChannelPlaylist", (data) => {this.changeDefaultTitlesChannelPlaylist(socket, data)});
|
||||
}
|
||||
|
||||
//--- USER-FACING PLAYLIST FUNCTIONS ---
|
||||
|
|
@ -64,6 +65,7 @@ module.exports = class{
|
|||
chanDB = await channelModel.findOne({name: this.channel.name});
|
||||
}
|
||||
|
||||
|
||||
//If the title is too long
|
||||
if(!validator.isLength(data.playlist, {max:30})){
|
||||
//Bitch, moan, complain...
|
||||
|
|
@ -75,10 +77,30 @@ module.exports = class{
|
|||
//Escape/trim the playlist name
|
||||
const name = validator.escape(validator.trim(data.playlist));
|
||||
|
||||
//If the channel already exists
|
||||
if(chanDB.getPlaylistByName(name) != null){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, `Playlist named '${name}' already exists!`, "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//Create empty array to hold titles
|
||||
const safeTitles = [];
|
||||
|
||||
//For each default title passed by the data
|
||||
for(let title of data.defaultTitles){
|
||||
//If the title isn't too long
|
||||
if(validator.isLength(title, {min:1, max:30})){
|
||||
//Add it to the safe title list
|
||||
safeTitles.push(validator.escape(validator.trim(title)))
|
||||
}
|
||||
}
|
||||
|
||||
//Add playlist to the channel doc
|
||||
chanDB.media.playlists.push({
|
||||
name,
|
||||
defaultTitles: data.defaultTitles
|
||||
defaultTitles: safeTitles
|
||||
});
|
||||
|
||||
//Save the channel doc
|
||||
|
|
@ -209,6 +231,14 @@ module.exports = class{
|
|||
//Escape/trim the playlist name
|
||||
const name = validator.escape(validator.trim(data.name));
|
||||
|
||||
//If the channel already exists
|
||||
if(chanDB.getPlaylistByName(name) != null){
|
||||
//Bitch, moan, complain...
|
||||
loggerUtils.socketErrorHandler(socket, `Playlist named '${name}' already exists!`, "validation");
|
||||
//and ignore it!
|
||||
return;
|
||||
}
|
||||
|
||||
//Find playlist
|
||||
let playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
|
|
@ -224,4 +254,40 @@ module.exports = class{
|
|||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
}
|
||||
}
|
||||
|
||||
async changeDefaultTitlesChannelPlaylist(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});
|
||||
}
|
||||
|
||||
//Find playlist
|
||||
let playlist = chanDB.getPlaylistByName(data.playlist);
|
||||
|
||||
//Create empty array to hold titles
|
||||
const safeTitles = [];
|
||||
|
||||
//For each default title passed by the data
|
||||
for(let title of data.defaultTitles){
|
||||
//If the title isn't too long or too short
|
||||
if(validator.isLength(title, {min: 1, max:30})){
|
||||
//Add it to the safe title list
|
||||
safeTitles.push(validator.escape(validator.trim(title)))
|
||||
}
|
||||
}
|
||||
|
||||
//Change playlist name
|
||||
chanDB.media.playlists[playlist.listIndex].defaultTitles = safeTitles;
|
||||
|
||||
//Save channel document
|
||||
await chanDB.save();
|
||||
|
||||
//Return playlists from channel doc
|
||||
socket.emit('chanPlaylists', chanDB.getPlaylists());
|
||||
}catch(err){
|
||||
return loggerUtils.socketExceptionHandler(socket, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue