Moving currently playing items to an invalid spot in the schedule no longer creates ghost items.

This commit is contained in:
rainbow napkin 2025-10-28 07:03:16 -04:00
parent a1f0824330
commit 349a6b82aa

View file

@ -642,6 +642,8 @@ class queue{
//Find our media, don't remove it yet since we want to do some more testing first //Find our media, don't remove it yet since we want to do some more testing first
let media = this.getItemByUUID(uuid); 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 we got a bad request
if(media == null){ if(media == null){
@ -658,6 +660,8 @@ class queue{
if(media.startTime < new Date().getTime()){ if(media.startTime < new Date().getTime()){
//If the item is currently playing //If the item is currently playing
if(media.getEndTime() > new Date().getTime()){ if(media.getEndTime() > new Date().getTime()){
//Set old media
oldMedia = media;
//Dupe media for the rest of the function //Dupe media for the rest of the function
media = media.clone(); media = media.clone();
@ -699,6 +703,13 @@ class queue{
//Reset the start time stamp for re-calculation //Reset the start time stamp for re-calculation
media.startTimeStamp = 0; 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 //Schedule in old slot with noSave enabled
await this.scheduleMedia([media], socket, chanDB, true); await this.scheduleMedia([media], socket, chanDB, true);
} }
@ -721,7 +732,7 @@ class queue{
* @param {String} uuid - UUID of item to reschedule * @param {String} uuid - UUID of item to reschedule
* @param {Socket} socket - Requesting Socket * @param {Socket} socket - Requesting Socket
* @param {Mongoose.Document} chanDB - Channnel Document Passthrough to save on DB Access * @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 * @returns {Media} Deleted Media Item
*/ */
async removeMedia(uuid, socket, chanDB, noScheduling = false){ async removeMedia(uuid, socket, chanDB, noScheduling = false){
@ -773,8 +784,12 @@ class queue{
}else{ }else{
//Broadcast changes //Broadcast changes
this.broadcastQueue(chanDB); 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){ }catch(err){
//If this was originated by someone //If this was originated by someone