Continued work on playlist management UI

This commit is contained in:
rainbow napkin 2025-04-03 01:43:19 -04:00
parent 04dec153ac
commit c3781d6259
7 changed files with 201 additions and 32 deletions

View file

@ -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);
}
}
}

View file

@ -29,7 +29,7 @@ const playlistSchema = new mongoose.Schema({
media: [playlistMediaSchema],
defaultTitles:[{
type: mongoose.SchemaTypes.String,
required: true,
required: false,
default: []
}]
});

View file

@ -0,0 +1,21 @@
<%# Canopy - The next generation of stoner streaming software
Copyright (C) 2024-2025 Rainbownapkin and the TTN Community
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. %>
<link rel="stylesheet" type="text/css" href="/css/popup/playlistDefaultTitles.css">
<h3 class="popup-title">Edit Playlist Default Titles</h3>
<div id="playlist-default-titles-popup-div">
<textarea id="playlist-default-titles-popup-prompt"></textarea>
<button class="positive-button" id="playlist-default-media-popup-button">Change Titles</button>
</div>

View file

@ -0,0 +1,21 @@
<%# Canopy - The next generation of stoner streaming software
Copyright (C) 2024-2025 Rainbownapkin and the TTN Community
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. %>
<%# <link rel="stylesheet" type="text/css" href="/css/popup/schedule.css"> %>
<h3 class="popup-title">Rename Playlist</h3>
<div>
<input id="playlist-rename-popup-prompt" placeholder="New Name">
<button class="positive-button" id="playlist-rename-popup-button">Rename Playlist</button>
</div>