Started work on playlist management UI

This commit is contained in:
rainbow napkin 2025-03-30 14:11:49 -04:00
parent 65b5ae9371
commit 1723e8ebd0
9 changed files with 586 additions and 104 deletions

View file

@ -559,10 +559,7 @@ channelSchema.methods.getPlaylists = function(){
//this.media.playlists.forEach((playlist) => {
for(let playlist of this.media.playlists){
//Push an object with select information from the emote to the emote list
playlists.push({
name: playlist.name,
count: playlist.media.length
});
playlists.push(playlist.dehydrate());
}
//return the emote list
@ -584,11 +581,13 @@ channelSchema.methods.getPlaylistByName = function(name){
let foundPlaylist = null;
//Crawl through active playlists
this.playlistCrawl((playlist) => {
this.playlistCrawl((playlist, listIndex) => {
//If we found a match based on name
if(playlist.name == name){
//Keep it
foundPlaylist = playlist;
//Pass down the list index
foundPlaylist.listIndex = listIndex;
}
});
@ -597,45 +596,25 @@ channelSchema.methods.getPlaylistByName = function(name){
}
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;
}
});
//Find the playlist
let playlist = this.getPlaylistByName(name);
//splice out the given playlist
this.media.playlists.splice(foundIndex, 1);
this.media.playlists.splice(playlist.listIndex, 1);
//save the channel document
await this.save();
}
channelSchema.methods.addToPlaylist = async function(name, media){
//Create variable to hold found index
let foundIndex = null
//Crawl through active playlists
this.playlistCrawl((playlist, listIndex) => {
//If the playlist name matches
if(playlist.name == name){
//Push the given media into the found playlist
//Make note of the found index
foundIndex = listIndex
}
});
//Find the playlist
let playlist = this.getPlaylistByName(name);
//Set media status schema discriminator
media.status = 'saved';
//Add the media to the playlist
this.media.playlists[foundIndex].media.push(media);
this.media.playlists[playlist.listIndex].media.push(media);
//Save the changes made to the chan doc
await this.save();

View file

@ -24,6 +24,7 @@ const playlistSchema = new mongoose.Schema({
name: {
type: mongoose.SchemaTypes.String,
required: true,
unique: true
},
media: [playlistMediaSchema],
defaultTitles:[{
@ -33,8 +34,26 @@ const playlistSchema = new mongoose.Schema({
}]
});
playlistSchema.methods.test = function(){
console.log(this.name);
//methods
playlistSchema.methods.dehydrate = function(){
//Create empty array to hold media
const mediaArray = [];
//Fill media array
for(let media of this.media){
mediaArray.push({
title: media.title,
url: media.url,
duration: media.duration
});
}
//return dehydrated playlist
return {
name: this.name,
media: mediaArray,
defaultTitles: this.defaultTitles
}
}
module.exports = playlistSchema;