Updated queue to save archived media to site-wide collection

This commit is contained in:
rainbow napkin 2026-05-29 08:06:46 -04:00
parent 855343dfc3
commit 4dbc5b69cf
2 changed files with 42 additions and 7 deletions

View file

@ -65,6 +65,28 @@ class archivedMedia extends queuedMedia{
channel); channel);
} }
/**
* Creates a archivedMedia object from a queuedMedia object
* @param {String} channel - Channel where object was queued
* @returns {archivedMedia} queuedMedia object created from given media object
*/
static fromQueuedMedia(media, channel){
//Create and return queuedMedia object from given media object and arguments
return new this(
media.title,
media.fileName,
media.url,
media.id,
media.type,
media.duration,
media.rawLink,
media.startTime,
media.startTimeStamp,
media.earlyEnd,
null,
channel);
}
/** /**
* Converts array of media objects into array of archivedMedia objects * Converts array of media objects into array of archivedMedia objects
* @param {String} channel - Channel where object was queued * @param {String} channel - Channel where object was queued

View file

@ -20,10 +20,12 @@ const validator = require('validator');
//Local imports //Local imports
const config = require('../../../../config.json'); const config = require('../../../../config.json');
const queuedMedia = require('./queuedMedia'); const queuedMedia = require('./queuedMedia');
const archivedMedia = require('./archivedMedia');
const yanker = require('../../../utils/media/yanker'); const yanker = require('../../../utils/media/yanker');
const loggerUtils = require('../../../utils/loggerUtils'); const loggerUtils = require('../../../utils/loggerUtils');
const channelModel = require('../../../schemas/channel/channelSchema'); const channelModel = require('../../../schemas/channel/channelSchema');
const permissionModel = require('../../../schemas/permissionSchema'); const permissionModel = require('../../../schemas/permissionSchema');
const archivedMediaModel = require('../../../schemas/channel/media/archivedMediaSchema');
/** /**
* Object represneting a single channel's media queue * Object represneting a single channel's media queue
@ -767,7 +769,7 @@ class queue{
//Get requested media //Get requested media
const media = this.getItemByUUID(uuid); const media = this.getItemByUUID(uuid);
//If we got a bad request //If we couldn't find anything in the current channel schedule
if(media == null){ if(media == null){
try{ try{
//If we wheren't handed a channel //If we wheren't handed a channel
@ -1145,7 +1147,7 @@ class queue{
//If nowPlaying isn't null and isn't what we're about to throw on //If nowPlaying isn't null and isn't what we're about to throw on
if(chanDB.media.nowPlaying != null && chanDB.media.nowPlaying.uuid.toString() != mediaObj.uuid){ if(chanDB.media.nowPlaying != null && chanDB.media.nowPlaying.uuid.toString() != mediaObj.uuid){
//Archive whats already in there since we're about to clobber the fuck out of it //Archive whats already in there since we're about to clobber the fuck out of it
chanDB.media.archived.push(chanDB.media.nowPlaying); this.archiveMedia(chanDB.media.nowPlaying);
} }
//Set the now playing queued media document //Set the now playing queued media document
@ -1284,7 +1286,7 @@ class queue{
//If archiving is enabled //If archiving is enabled
if(!noArchive){ if(!noArchive){
//Add the item to the channel archive //Add the item to the channel archive
chanDB.media.archived.push(wasPlaying); this.archiveMedia(wasPlaying);
} }
//broadcast queue using unsaved archive, run this before chanDB.save() for better responsiveness //broadcast queue using unsaved archive, run this before chanDB.save() for better responsiveness
@ -1383,7 +1385,7 @@ class queue{
let finished = false; let finished = false;
//Throw the livestream into the archive //Throw the livestream into the archive
chanDB.media.archived.push(wasPlaying); this.archiveMedia(wasPlaying);
//Save the DB //Save the DB
await chanDB.save(); await chanDB.save();
@ -1468,7 +1470,7 @@ class queue{
} }
//Throw the livestream into the archive //Throw the livestream into the archive
chanDB.media.archived.push(wasPlaying); this.archiveMedia(wasPlaying);
//Set the current place to schedule items at 5ms after the end of the live stream //Set the current place to schedule items at 5ms after the end of the live stream
let curPlace = wasPlaying.getEndTime() + 5; let curPlace = wasPlaying.getEndTime() + 5;
@ -1810,7 +1812,7 @@ class queue{
chanDB.media.nowPlaying = null; chanDB.media.nowPlaying = null;
//Archive the bitch //Archive the bitch
chanDB.media.archived.push(wasPlaying); this.archiveMedia(wasPlaying);
} }
} }
@ -1840,7 +1842,7 @@ class queue{
//If it's been ended //If it's been ended
}else{ }else{
//Archive ended media //Archive ended media
chanDB.media.archived.push(record); this.archiveMedia(record);
} }
} }
} }
@ -1892,6 +1894,17 @@ class queue{
loggerUtils.localExceptionHandler(err); loggerUtils.localExceptionHandler(err);
} }
} }
/**
* Commits a queuedMedia object to the media archives
* @param {queuedMedia} media - Media object to be archived
*/
async archiveMedia(media){
//Convert queuedMedia object to archivedMedia object
let archived = archivedMedia.fromQueuedMedia(media, this.channel.name);
//Save archivedMedia object to site-wide media archive (gross but performant)
let archivedDoc = await archivedMediaModel.create(archived);
}
} }
module.exports = queue; module.exports = queue;