Created Playlist Media Schema.
This commit is contained in:
parent
cb09c139c7
commit
59f097db39
4 changed files with 66 additions and 4 deletions
60
src/schemas/channel/media/playlistMediaSchema.js
Normal file
60
src/schemas/channel/media/playlistMediaSchema.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*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/>.*/
|
||||
|
||||
//NPM Imports
|
||||
const {mongoose} = require('mongoose');
|
||||
|
||||
//Local Imports
|
||||
const mediaSchema = require('./mediaSchema');
|
||||
const media = require('../../../app/channel/media/media');
|
||||
|
||||
const playlistMediaProperties = new mongoose.Schema({
|
||||
uuid: {
|
||||
type: mongoose.SchemaTypes.UUID,
|
||||
required:true,
|
||||
unique: true
|
||||
}
|
||||
},
|
||||
{
|
||||
discriminatorKey: 'status'
|
||||
});
|
||||
|
||||
//Schema Middleware
|
||||
playlistMediaProperties.pre('save', async function (next){
|
||||
//If the UUID was modified in anyway
|
||||
if(this.isModified("uuid")){
|
||||
//Throw that shit out and make a new one since it's probably either null or a leftover from some channel queue
|
||||
this.uuid = crypto.randomUUID();
|
||||
}
|
||||
|
||||
//Keep it moving
|
||||
next();
|
||||
});
|
||||
|
||||
//methods
|
||||
playlistMediaProperties.methods.rehydrate = function(){
|
||||
//Return item as a full phat, standard media object
|
||||
return new media(
|
||||
this.title,
|
||||
this.fileName,
|
||||
this.url,
|
||||
this.id,
|
||||
this.type,
|
||||
this.duration
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = mediaSchema.discriminator('saved', playlistMediaProperties);
|
||||
|
|
@ -18,14 +18,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
const {mongoose} = require('mongoose');
|
||||
|
||||
//Local Imports
|
||||
const mediaSchema = require('./mediaSchema');
|
||||
const playlistMediaSchema = require('./playlistMediaSchema');
|
||||
|
||||
module.exports = new mongoose.Schema({
|
||||
name: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
},
|
||||
media: [mediaSchema],
|
||||
media: [playlistMediaSchema],
|
||||
defaultTitles:[{
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ const queuedProperties = new mongoose.Schema({
|
|||
});
|
||||
|
||||
//methods
|
||||
//Rehydrate to a full phat queued media object
|
||||
queuedProperties.methods.rehydrate = function(){
|
||||
return new queuedMedia(
|
||||
this.title,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue