From 349a6b82aab76a0948e20f681663a491d7df7f58 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Tue, 28 Oct 2025 07:03:16 -0400 Subject: [PATCH] Moving currently playing items to an invalid spot in the schedule no longer creates ghost items. --- src/app/channel/media/queue.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app/channel/media/queue.js b/src/app/channel/media/queue.js index f52d75c..3905702 100644 --- a/src/app/channel/media/queue.js +++ b/src/app/channel/media/queue.js @@ -642,6 +642,8 @@ class queue{ //Find our media, don't remove it yet since we want to do some more testing first let media = this.getItemByUUID(uuid); + //Create value to hold old media in-case somethin' fucks up + let oldMedia = null; //If we got a bad request if(media == null){ @@ -658,6 +660,8 @@ class queue{ if(media.startTime < new Date().getTime()){ //If the item is currently playing if(media.getEndTime() > new Date().getTime()){ + //Set old media + oldMedia = media; //Dupe media for the rest of the function media = media.clone(); @@ -699,6 +703,13 @@ class queue{ //Reset the start time stamp for re-calculation media.startTimeStamp = 0; + //If there's a cut-off from moving a now-playing item + if(oldMedia != null){ + //Remove it from the queue to prevent ghost items + this.removeMedia(oldMedia.uuid, socket, chanDB, true); + } + + //Schedule in old slot with noSave enabled await this.scheduleMedia([media], socket, chanDB, true); } @@ -721,7 +732,7 @@ class queue{ * @param {String} uuid - UUID of item to reschedule * @param {Socket} socket - Requesting Socket * @param {Mongoose.Document} chanDB - Channnel Document Passthrough to save on DB Access - * @param {Boolean} noScheduling - Disables schedule timer refresh if true + * @param {Boolean} noScheduling - Disables schedule timer refresh and this.save() calls if true, good for internal function calls * @returns {Media} Deleted Media Item */ async removeMedia(uuid, socket, chanDB, noScheduling = false){ @@ -773,8 +784,12 @@ class queue{ }else{ //Broadcast changes this.broadcastQueue(chanDB); - //Save changes to the DB - await chanDB.save(); + + //If saving is disabled + if(!noScheduling){ + //Save changes to the DB + await chanDB.save(); + } } }catch(err){ //If this was originated by someone