Finished JSDoc for src/schemas/channel/media
This commit is contained in:
parent
b78d35d0f8
commit
ec37c2f59d
|
|
@ -17,6 +17,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
//NPM Imports
|
//NPM Imports
|
||||||
const {mongoose} = require('mongoose');
|
const {mongoose} = require('mongoose');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DB Schema representing a single piece of media
|
||||||
|
*/
|
||||||
const mediaSchema = new mongoose.Schema({
|
const mediaSchema = new mongoose.Schema({
|
||||||
title: {
|
title: {
|
||||||
type: mongoose.SchemaTypes.String,
|
type: mongoose.SchemaTypes.String,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ const {mongoose} = require('mongoose');
|
||||||
const mediaSchema = require('./mediaSchema');
|
const mediaSchema = require('./mediaSchema');
|
||||||
const media = require('../../../app/channel/media/media');
|
const media = require('../../../app/channel/media/media');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DB Schema for documents represnting a piece of media held in a playlist
|
||||||
|
*/
|
||||||
const playlistMediaProperties = new mongoose.Schema({
|
const playlistMediaProperties = new mongoose.Schema({
|
||||||
uuid: {
|
uuid: {
|
||||||
type: mongoose.SchemaTypes.UUID,
|
type: mongoose.SchemaTypes.UUID,
|
||||||
|
|
@ -33,6 +36,9 @@ const playlistMediaProperties = new mongoose.Schema({
|
||||||
});
|
});
|
||||||
|
|
||||||
//Schema Middleware
|
//Schema Middleware
|
||||||
|
/**
|
||||||
|
* Pre-save function for playlist meda, ensures unique UUID
|
||||||
|
*/
|
||||||
playlistMediaProperties.pre('save', async function (next){
|
playlistMediaProperties.pre('save', async function (next){
|
||||||
//If the UUID was modified in anyway
|
//If the UUID was modified in anyway
|
||||||
if(this.isModified("uuid")){
|
if(this.isModified("uuid")){
|
||||||
|
|
@ -45,7 +51,10 @@ playlistMediaProperties.pre('save', async function (next){
|
||||||
});
|
});
|
||||||
|
|
||||||
//methods
|
//methods
|
||||||
//Rehydrate to a full phat media object
|
/**
|
||||||
|
* Rehydrate to a full phat media object
|
||||||
|
* @returns {media} A full phat media object, re-hydrated from the DB
|
||||||
|
*/
|
||||||
playlistMediaProperties.methods.rehydrate = function(){
|
playlistMediaProperties.methods.rehydrate = function(){
|
||||||
//Return item as a full phat, standard media object
|
//Return item as a full phat, standard media object
|
||||||
return new media(
|
return new media(
|
||||||
|
|
@ -58,7 +67,10 @@ playlistMediaProperties.methods.rehydrate = function(){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dehydrate to minified flat network-friendly object
|
/**
|
||||||
|
* Dehydrate to minified flat network-friendly object
|
||||||
|
* @returns {Object} Network-Friendly Browser-Digestable object representing media from a playlist
|
||||||
|
*/
|
||||||
playlistMediaProperties.methods.dehydrate = function(){
|
playlistMediaProperties.methods.dehydrate = function(){
|
||||||
return {
|
return {
|
||||||
title: this.title,
|
title: this.title,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ const {mongoose} = require('mongoose');
|
||||||
//Local Imports
|
//Local Imports
|
||||||
const playlistMediaSchema = require('./playlistMediaSchema');
|
const playlistMediaSchema = require('./playlistMediaSchema');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DB Schema for Documents representing playlists full of media
|
||||||
|
*/
|
||||||
const playlistSchema = new mongoose.Schema({
|
const playlistSchema = new mongoose.Schema({
|
||||||
name: {
|
name: {
|
||||||
type: mongoose.SchemaTypes.String,
|
type: mongoose.SchemaTypes.String,
|
||||||
|
|
@ -34,6 +37,10 @@ const playlistSchema = new mongoose.Schema({
|
||||||
});
|
});
|
||||||
|
|
||||||
//methods
|
//methods
|
||||||
|
/**
|
||||||
|
* Dehydrate to minified flat network-friendly object
|
||||||
|
* @returns {Object} Network-Friendly Browser-Digestable object representing media from a playlist
|
||||||
|
*/
|
||||||
playlistSchema.methods.dehydrate = function(){
|
playlistSchema.methods.dehydrate = function(){
|
||||||
//Create empty array to hold media
|
//Create empty array to hold media
|
||||||
const mediaArray = [];
|
const mediaArray = [];
|
||||||
|
|
@ -51,6 +58,10 @@ playlistSchema.methods.dehydrate = function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add media to the given playlist Document
|
||||||
|
* @param {Array} mediaList - Array of media Objects to add to playlist
|
||||||
|
*/
|
||||||
playlistSchema.methods.addMedia = function(mediaList){
|
playlistSchema.methods.addMedia = function(mediaList){
|
||||||
//For every piece of media in the list
|
//For every piece of media in the list
|
||||||
for(let media of mediaList){
|
for(let media of mediaList){
|
||||||
|
|
@ -62,6 +73,11 @@ playlistSchema.methods.addMedia = function(mediaList){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets Media from a playlist by UUID
|
||||||
|
* @param {String} uuid - UUID of media to pull
|
||||||
|
* @returns {media} media with matching UUID
|
||||||
|
*/
|
||||||
playlistSchema.methods.findMediaByUUID = function(uuid){
|
playlistSchema.methods.findMediaByUUID = function(uuid){
|
||||||
//For every piece of media in the current playlist
|
//For every piece of media in the current playlist
|
||||||
for(let media of this.media){
|
for(let media of this.media){
|
||||||
|
|
@ -73,6 +89,10 @@ playlistSchema.methods.findMediaByUUID = function(uuid){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes media from a given playlist
|
||||||
|
* @param {String} uuid - UUID of media to delete
|
||||||
|
*/
|
||||||
playlistSchema.methods.deleteMedia = function(uuid){
|
playlistSchema.methods.deleteMedia = function(uuid){
|
||||||
//Create new array to hold list of media to be kept
|
//Create new array to hold list of media to be kept
|
||||||
const keptMedia = [];
|
const keptMedia = [];
|
||||||
|
|
@ -90,6 +110,11 @@ playlistSchema.methods.deleteMedia = function(uuid){
|
||||||
this.media = keptMedia;
|
this.media = keptMedia;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pick title based on default title's list and media's given title
|
||||||
|
* @param {String} title - Title to use if there are no default titles.
|
||||||
|
* @returns {String} Chosen title based on result of function
|
||||||
|
*/
|
||||||
playlistSchema.methods.pickDefaultTitle = function(title){
|
playlistSchema.methods.pickDefaultTitle = function(title){
|
||||||
//If we don't have default titles in this playlist
|
//If we don't have default titles in this playlist
|
||||||
if(this.defaultTitles.length <= 0){
|
if(this.defaultTitles.length <= 0){
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ const {mongoose} = require('mongoose');
|
||||||
const mediaSchema = require('./mediaSchema');
|
const mediaSchema = require('./mediaSchema');
|
||||||
const queuedMedia = require('../../../app/channel/media/queuedMedia');
|
const queuedMedia = require('../../../app/channel/media/queuedMedia');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DB Schema for documents representing a queued media object
|
||||||
|
*/
|
||||||
const queuedProperties = new mongoose.Schema({
|
const queuedProperties = new mongoose.Schema({
|
||||||
startTime: {
|
startTime: {
|
||||||
type: mongoose.SchemaTypes.Number,
|
type: mongoose.SchemaTypes.Number,
|
||||||
|
|
@ -44,7 +47,10 @@ const queuedProperties = new mongoose.Schema({
|
||||||
});
|
});
|
||||||
|
|
||||||
//Methods
|
//Methods
|
||||||
//Rehydrate to a full phat queued media object
|
/**
|
||||||
|
* Rehydrate to a full phat queued media object
|
||||||
|
* @returns {queuedMedia} A full phat queued media object, re-hydrated from the DB
|
||||||
|
*/
|
||||||
queuedProperties.methods.rehydrate = function(){
|
queuedProperties.methods.rehydrate = function(){
|
||||||
return new queuedMedia(
|
return new queuedMedia(
|
||||||
this.title,
|
this.title,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue