diff --git a/src/app/channel/media/queue.js b/src/app/channel/media/queue.js index 6ad6697..d5627d9 100644 --- a/src/app/channel/media/queue.js +++ b/src/app/channel/media/queue.js @@ -17,6 +17,7 @@ along with this program. If not, see .*/ //NPM imports const validator = require('validator'); const mongoose = require('mongoose'); +const { BSON } = require('mongodb'); //Local imports const config = require('../../../../config.json'); @@ -775,29 +776,11 @@ class queue{ //If we couldn't find anything in the current channel schedule if(media == null){ try{ - //If we wheren't handed a channel - if(chanDB == null){ - //DO everything ourselves since we don't have a fance end() function to do it - chanDB = await channelModel.findOne({name:this.channel.name}); - } + //Attempt to delete matching item from archived media + const deletedArchive = await archivedMediaModel.deleteOne({channel: this.channel.name, uuid: new BSON.UUID(uuid)}); - //If we couldn't find the channel - if(chanDB == null){ - //FUCK - throw loggerUtils.exceptionSmith(`Unable to find channel document ${this.channel.name} while queue item!`, "queue"); - } - - //Keep a copy of the archive that hasn't been changed - const preArchive = await this.getArchive(); - - //This logic wont work since we cant just set the archive as an array anymore, maybe using mongoose.delete finding by channel and uuid? - //Filter out the requested item from the archive - /*chanDB.media.archived = chanDB.media.archived.filter((record)=>{ - return record.uuid.toString() != uuid; - })*/ - - //If nothing changed in the archive - if(preArchive.length == chanDB.media.archived.length){ + //if nothing got deleted + if(deletedArchive == null || deletedArchive.deletedCount == 0){ //If an originating socket was provided for this request if(socket != null){ //Yell at the user for being an asshole @@ -808,13 +791,7 @@ class queue{ //If broadcasting is enabled if(!noBroadcast){ //Broadcast changes - this.broadcastQueue(chanDB); - } - - //If saving is disabled - if(!noScheduling){ - //Save changes to the DB - await chanDB.save(); + this.broadcastQueue(); } } }catch(err){