From 50b1e15a6cc793b15461e9148d95240bb8423880 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Mon, 12 Oct 2026 01:10:34 -0400 Subject: [PATCH] Updated scheduler to display schedule archives upon request. --- src/app/channel/media/queue.js | 8 ++++ www/js/channel/channel.js | 37 +++++++++++++++++++ .../channel/panels/queuePanel/queuePanel.js | 17 ++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/app/channel/media/queue.js b/src/app/channel/media/queue.js index 6a6059b..f74b0f0 100644 --- a/src/app/channel/media/queue.js +++ b/src/app/channel/media/queue.js @@ -533,6 +533,14 @@ class queue{ //Yeetus-Deletus bitch return; } + + //If our startDate isn't before our endDate + if(data.startDate >= data.endDate){ + //Bitch, moan, an' complain! + loggerUtils.socketErrorHandler(socket, "Invalid Date Range!", "validation"); + //Yeetus-Deletus bitch + return; + } //Get the current channel from the database const chanDB = await channelModel.findOne({name: socket.chan}); diff --git a/www/js/channel/channel.js b/www/js/channel/channel.js index 6b5e535..13d2bda 100644 --- a/www/js/channel/channel.js +++ b/www/js/channel/channel.js @@ -126,6 +126,10 @@ class channel{ this.queueBroadcastSocket.on("queue", (data) => { this.queue = new Map(data.queue); }); + + this.socket.on("archive", (data) =>{ + this.sortQueue(data.archive); + }) } /** @@ -157,6 +161,39 @@ class channel{ this.streamType = data.streamType; } + /** + * Sorts queue, optionally adding new items along the way + * @param {object} queueData - Contains list of entries to add to the queue + */ + sortQueue(queueData){ + //Create array to temporary sort schedule within + const tempSched = []; + //Get current queue as entries + let entries = Array.from(this.queue.entries()); + + //Blow-out existing queue since we've already pulled out the data we need from it + this.queue = new Map(); + + + //If we have new queue data + if(queueData != null){ + //Concat passed queue data to beggining of entries pulled from queue map + entries = queueData.concat(entries); + } + + //For each media entry accounted for + for(let entry of entries){ + //Store entry item in array indexed to its start epoch in seconds + tempSched[Math.round(entry[0] / 1000)] = entry[1]; + } + + //Iterate through populated indices of tempSched to skip over empty indexes, just like in the server-side + for(let startTime of Object.keys(tempSched)){ + //Add each entry to the queue in order of start time + this.queue.set(tempSched[startTime].startTime, tempSched[startTime]); + } + } + /** * Processes and applies default config on any unset settings * @param {Boolean} force - Whether or not to forcefully reset already set settings diff --git a/www/js/channel/panels/queuePanel/queuePanel.js b/www/js/channel/panels/queuePanel/queuePanel.js index 5f49000..50a9dee 100644 --- a/www/js/channel/panels/queuePanel/queuePanel.js +++ b/www/js/channel/panels/queuePanel/queuePanel.js @@ -142,7 +142,8 @@ class queuePanel extends panelObj{ defineListeners(){ //Render queue when we receive a new copy of the queue data from the server //Render queue should be called within an arrow function so that it's called with default parameters, and not handed an event as a date - this.client.queueBroadcastSocket.on("queue", () => {this.renderQueue();}); + this.client.queueBroadcastSocket.on("queue", this.renderQueue.bind(this)); + this.client.socket.on("archive", this.renderQueue.bind(this)); this.client.socket.on("start", this.handleStart.bind(this)); this.client.socket.on("end", this.handleEnd.bind(this)); this.client.socket.on("lock", this.handleScheduleLock.bind(this)); @@ -491,6 +492,20 @@ class queuePanel extends panelObj{ //Re-render/hide the time marker this.renderTimeMarker(); + //If we're not looking at today + if(!utils.isSameDate(date, new Date())){ + //Clone given epoch twice + const dayBefore = new Date(date.getTime()); + const dayAfter = new Date(date.getTime()); + + //Make it a day before/after + dayBefore.setDate(dayBefore.getDate() - 1); + dayAfter.setDate(dayAfter.getDate() + 1); + + //Request the archives from that day + this.client.socket.emit("getArchive", {startDate: dayBefore.getTime(), endDate: dayAfter.getTime()}); + } + //If autoscroll is enabled if(this.autoscroll){ //Simulate a button click to un/re-light the button and trigger a scroll when the date is set to today