Started work on JSDoc. src/app started, src/app/channel/media complete.

This commit is contained in:
rainbow napkin 2025-08-25 08:09:43 -04:00
parent c64b315fdf
commit fd760e4dab
6 changed files with 467 additions and 32 deletions

View file

@ -24,14 +24,26 @@ const yanker = require('../../../utils/media/yanker');
const channelModel = require('../../../schemas/channel/channelSchema');
const { userModel } = require('../../../schemas/user/userSchema');
/**
* Class containing playlist management logic for a single channel
*/
module.exports = class{
constructor(server, chanDB, channel){
/**
* Instantiates a new object to handle playlist management for a single channel
* @param {channelManager} server - Parent server object
* @param {activeChannel} channel - Parent Channel object for desired channel queue
*/
constructor(server, channel){
//Set server
this.server = server
//Set channel
this.channel = channel;
}
/**
* Defines server-side socket.io listeners for newly connected sockets
* @param {Socket} socket - Newly connected socket to define listeners against
*/
defineListeners(socket){
//Channel Playlist Listeners
socket.on("getChannelPlaylists", () => {this.getChannelPlaylists(socket)});
@ -59,6 +71,12 @@ module.exports = class{
}
//Validation/Sanatization functions
/**
* Validates client requests to create a playlist
* @param {Socket} socket - Newly connected socket to define listeners against
* @param {Object} data - Data handed over from the client
* @returns {Object} returns validated titles
*/
createPlaylistValidator(socket, data){
//Create empty array to hold titles
const safeTitles = [];
@ -89,6 +107,12 @@ module.exports = class{
}
}
/**
* Validates client requests to add media to a playlist
* @param {Socket} socket - Newly connected socket to define listeners against
* @param {String} URL - URL String handed over from the client
* @returns {Array} List of media objects which where added
*/
async addToPlaylistValidator(socket, url){
//If we where given a bad URL
if(typeof url != 'string' || !validator.isURL(url)){
@ -118,6 +142,12 @@ module.exports = class{
return mediaList;
}
/**
* Validates client requests to queue media from a playlist
* @param {Socket} socket - Newly connected socket to define listeners against
* @param {Object} data - Data handed over from the client
* @returns {Number} returns validated start time on success
*/
queueFromChannelPlaylistValidator(socket, data){
//Validate UUID
if(typeof data.uuid != 'string' || !validator.isUUID(data.uuid)){
@ -131,6 +161,12 @@ module.exports = class{
return this.channel.queue.getStart(data.start)
}
/**
* Validates client requests to rename the playlist validator
* @param {Socket} socket - Newly connected socket to define listeners against
* @param {Object} data - Data handed over from the client
* @returns {String} returns escaped/trimmed name upon success
*/
renameChannelPlaylistValidator(socket, data){
//If the title is too long
if(typeof data.name != 'string' || !validator.isLength(data.name, {min: 1, max:30})){
@ -144,6 +180,11 @@ module.exports = class{
return validator.escape(validator.trim(data.name));
}
/**
* Validates client requests to change default titles for a given playlist
* @param {Object} data - Data handed over from the client
* @returns
*/
changeDefaultTitlesValidator(data){
//Create empty array to hold titles
const safeTitles = [];
@ -161,6 +202,11 @@ module.exports = class{
return safeTitles;
}
/**
* Validates client requests to rename the playlist validator
* @param {Socket} socket - Newly connected socket to define listeners against
* @param {Object} data - Data handed over from the client
*/
deletePlaylistMediaValidator(socket, data){
//If we don't have a valid UUID
if(typeof data.uuid != 'string' || !validator.isUUID(data.uuid)){
@ -174,6 +220,11 @@ module.exports = class{
}
//Get playlist functions
/**
* Sends channel playlist data to a requesting socket
* @param {Socket} socket - Newly connected socket to define listeners against
* @param {Mongoose.Document} chanDB - Channnel Document Passthrough to save on DB Access
*/
async getChannelPlaylists(socket, chanDB){
try{
//if we wherent handed a channel document
@ -189,6 +240,11 @@ module.exports = class{
}
}
/**
* Sends user playlist data to a requesting socket
* @param {Socket} socket - Newly connected socket to define listeners against
* @param {Mongoose.Document} userDB - Channnel Document Passthrough to save on DB Access
*/
async getUserPlaylists(socket, userDB){
try{
//if we wherent handed a user document
@ -205,6 +261,12 @@ module.exports = class{
}
//Create playlist functions
/**
* Creates a new channel playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} chanDB - Channnel Document Passthrough to save on DB Access
*/
async createChannelPlaylist(socket, data, chanDB){
try{
//Validate Data
@ -248,6 +310,12 @@ module.exports = class{
}
}
/**
* Creates a new user playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access
*/
async createUserPlaylist(socket, data, userDB){
try{
//Validate Data
@ -290,6 +358,12 @@ module.exports = class{
}
//Delete playlist functions
/**
* Deletes a user playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access
*/
async deleteChannelPlaylist(socket, data, chanDB){
try{
//if we wherent handed a channel document
@ -318,6 +392,12 @@ module.exports = class{
}
}
/**
* Deletes a Channel playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} chanDB - Channnel Document Passthrough to save on DB Access
*/
async deleteUserPlaylist(socket, data, userDB){
try{
//if we wherent handed a user document
@ -345,6 +425,12 @@ module.exports = class{
}
//Add Media Functions
/**
* Adds media to channel playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} chanDB - Channnel Document Passthrough to save on DB Access
*/
async addToChannelPlaylist(socket, data, chanDB){
try{
//if we wherent handed a channel document
@ -390,6 +476,12 @@ module.exports = class{
}
}
/**
* Adds media to user playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access
*/
async addToUserPlaylist(socket, data, userDB){
try{
//Validate URL and pull media
@ -432,6 +524,12 @@ module.exports = class{
}
//Queuing Functions
/**
* Queues an entire channel playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} chanDB - Channel Document Passthrough to save on DB Access
*/
async queueChannelPlaylist(socket, data, chanDB){
try{
//if we wherent handed a channel document
@ -479,6 +577,13 @@ module.exports = class{
}
}
/**
* Queues an entire user playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access
* @param {Mongoose.Document} chanDB - Channel Document Passthrough to save on DB Access
*/
async queueUserPlaylist(socket, data, userDB, chanDB){
try{
//if we wherent handed a user document
@ -532,6 +637,12 @@ module.exports = class{
}
}
/**
* Queues media from a given channel playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} chanDB - Channel Document Passthrough to save on DB Access
*/
async queueFromChannelPlaylist(socket, data, chanDB){
try{
//Validate data
@ -576,6 +687,13 @@ module.exports = class{
}
}
/**
* Queues media from a given user playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access
* @param {Mongoose.Document} chanDB - Channel Document Passthrough to save on DB Access
*/
async queueFromUserPlaylist(socket, data, userDB, chanDB){
try{
//Validate data
@ -626,6 +744,12 @@ module.exports = class{
}
}
/**
* Queues random media from a given channel playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} chanDB - Channel Document Passthrough to save on DB Access
*/
async queueRandomFromChannelPlaylist(socket, data, chanDB){
try{
//if we wherent handed a channel document
@ -667,6 +791,13 @@ module.exports = class{
}
}
/**
* Queues random media from a given user playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access
* @param {Mongoose.Document} chanDB - Channel Document Passthrough to save on DB Access
*/
async queueRandomFromUserPlaylist(socket, data, userDB, chanDB){
try{
//if we wherent handed a channel document
@ -715,6 +846,12 @@ module.exports = class{
}
//Rename playlist functions
/**
* Renames a channel playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} chanDB - Channel Document Passthrough to save on DB Access
*/
async renameChannelPlaylist(socket, data, chanDB){
try{
//Validate and Sanatize name
@ -766,6 +903,12 @@ module.exports = class{
}
}
/**
* Renames a user playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access
*/
async renameUserPlaylist(socket, data, userDB){
try{
//Validate and Sanatize name
@ -816,6 +959,12 @@ module.exports = class{
}
//Change default title list functions
/**
* Changes default titles for a given channel playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} chanDB - Channel Document Passthrough to save on DB Access
*/
async changeDefaultTitlesChannelPlaylist(socket, data, chanDB){
try{
//if we wherent handed a channel document
@ -850,6 +999,12 @@ module.exports = class{
}
}
/**
* Changes default titles for a given user playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access
*/
async changeDefaultTitlesUserPlaylist(socket, data, userDB){
try{
//if we wherent handed a user document
@ -884,6 +1039,12 @@ module.exports = class{
}
//Delete playlist media functions
/**
* Deletes media from a given channel playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} chanDB - Channel Document Passthrough to save on DB Access
*/
async deleteChannelPlaylistMedia(socket, data, chanDB){
try{
//Validate UUID
@ -927,6 +1088,12 @@ module.exports = class{
}
}
/**
* Deletes media from a given user playlist
* @param {Socket} socket - Requesting socket
* @param {Object} data - Data handed over from the client
* @param {Mongoose.Document} userDB - User Document Passthrough to save on DB Access
*/
async deleteUserPlaylistMedia(socket, data, userDB){
try{
//Validate UUID