From 59f097db39f2030f947e431f589aba6537efac46 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Fri, 21 Mar 2025 07:32:37 -0400 Subject: [PATCH] Created Playlist Media Schema. --- README.md | 5 +- .../channel/media/playlistMediaSchema.js | 60 +++++++++++++++++++ src/schemas/channel/media/playlistSchema.js | 4 +- .../channel/media/queuedMediaSchema.js | 1 + 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/schemas/channel/media/playlistMediaSchema.js diff --git a/README.md b/README.md index 1cc7538..34b1871 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,17 @@ This new codebase intends to solve the following issues with the current CyTube - General Clunk - Less Unique Community Identity -Canopy intends to be a simple node/express.js app. It leverages yt-dlp and the internet archive cli utility for metadata gathering. Persistant storage is handled by mongodb, as it's document based nature inherintly works well for cleanly storing large config documents for user/channel settings, and the low use of inter-collection references within the canopy software. All hardcore security functions like session handling and password hashing are handled by industry-standard open source libraries such as express-sessions and bcrypt, however it IS hobbiest software, and it should be treated as such. +Canopy intends to be a simple node/express.js app. It leverages the piped and the internet archive REST api's, as well as yt-dlp, for metadata gathering. Persistant storage is handled by mongodb, as it's document based nature inherintly works well for cleanly storing large config documents for user/channel settings, and the low use of inter-collection references within the canopy software. All hardcore security functions like session handling, CSRF mitigation, and password hashing are handled by industry-standard open source libraries such as express-sessions, csrf-sync, and bcrypt, however it IS hobbiest software, and it should be treated as such. The Canopy codebase does not, and never will contain: - Advertisements (targetted or otherwise) - Proprietary Code - 'Analytics/Telemtry' spyware + - The use of video sources which require proprietary 'Digital ~~Rights Management~~ Ristricitons Malware' such as Widevine. Thirdparty media providers may or may not contain all of the above atrocities :P, always use an ad-blocker! Our current goal is to create a cleaner, more modern, purpose-built codebase that has feature-parity with the current version of fore.st, while writing improvements where possible. Once this is accomplished, and ourfore.st has been migrated, work will continue to re-create features from TTN, while also building completely new ones as well. ## License - Canopy is written by the community, and provided under the GNU Affero General Public License v3 in order to prevent Canopy from being used in proprietary software or shitcoin scams. \ No newline at end of file + Canopy is written by the community, and provided under the GNU Affero General Public License v3 in order to prevent Canopy from being used in proprietary software or shitcoin scams. \ No newline at end of file diff --git a/src/schemas/channel/media/playlistMediaSchema.js b/src/schemas/channel/media/playlistMediaSchema.js new file mode 100644 index 0000000..59c6c68 --- /dev/null +++ b/src/schemas/channel/media/playlistMediaSchema.js @@ -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 .*/ + +//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); \ No newline at end of file diff --git a/src/schemas/channel/media/playlistSchema.js b/src/schemas/channel/media/playlistSchema.js index cf92f8d..2dc6d0b 100644 --- a/src/schemas/channel/media/playlistSchema.js +++ b/src/schemas/channel/media/playlistSchema.js @@ -18,14 +18,14 @@ along with this program. If not, see .*/ 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, diff --git a/src/schemas/channel/media/queuedMediaSchema.js b/src/schemas/channel/media/queuedMediaSchema.js index aac45d5..85a3d88 100644 --- a/src/schemas/channel/media/queuedMediaSchema.js +++ b/src/schemas/channel/media/queuedMediaSchema.js @@ -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,