Updated prepQueue function to pull from site-wide archive colleciton. Started work on updating removeMedia function.
This commit is contained in:
parent
bbb3576a7d
commit
ae294b3f78
1 changed files with 42 additions and 23 deletions
|
|
@ -16,6 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//NPM imports
|
//NPM imports
|
||||||
const validator = require('validator');
|
const validator = require('validator');
|
||||||
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
//Local imports
|
//Local imports
|
||||||
const config = require('../../../../config.json');
|
const config = require('../../../../config.json');
|
||||||
|
|
@ -425,7 +426,7 @@ class queue{
|
||||||
//Pull the channel DB doc
|
//Pull the channel DB doc
|
||||||
const chanDB = await channelModel.findOne({name:this.channel.name});
|
const chanDB = await channelModel.findOne({name:this.channel.name});
|
||||||
//Pull archived media by channel name
|
//Pull archived media by channel name
|
||||||
const archived = await archivedMediaModel.find({channel:this.channel.name});
|
const archived = await this.getArchive();
|
||||||
|
|
||||||
//Cook and emit a new object from all of the data
|
//Cook and emit a new object from all of the data
|
||||||
socket.emit("dumpQueue", {
|
socket.emit("dumpQueue", {
|
||||||
|
|
@ -787,12 +788,13 @@ class queue{
|
||||||
}
|
}
|
||||||
|
|
||||||
//Keep a copy of the archive that hasn't been changed
|
//Keep a copy of the archive that hasn't been changed
|
||||||
const preArchive = chanDB.media.archived;
|
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
|
//Filter out the requested item from the archive
|
||||||
chanDB.media.archived = chanDB.media.archived.filter((record)=>{
|
/*chanDB.media.archived = chanDB.media.archived.filter((record)=>{
|
||||||
return record.uuid.toString() != uuid;
|
return record.uuid.toString() != uuid;
|
||||||
})
|
})*/
|
||||||
|
|
||||||
//If nothing changed in the archive
|
//If nothing changed in the archive
|
||||||
if(preArchive.length == chanDB.media.archived.length){
|
if(preArchive.length == chanDB.media.archived.length){
|
||||||
|
|
@ -1741,16 +1743,20 @@ class queue{
|
||||||
//Create an empty array to hold our schedule
|
//Create an empty array to hold our schedule
|
||||||
let schedule = [];
|
let schedule = [];
|
||||||
|
|
||||||
//Get yestedays epoch
|
//Get todays epoch
|
||||||
const yesterday = new Date().setDate(new Date().getDate() - 1);
|
const yesterday = new Date();
|
||||||
|
|
||||||
|
//Make it yesterdays
|
||||||
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
|
|
||||||
|
//Get archive since yesterday
|
||||||
|
const archive = await this.getArchive(yesterday);
|
||||||
|
|
||||||
//Iterate through the channel archive backwards to save time
|
//Iterate through the channel archive backwards to save time
|
||||||
for(let mediaIndex = chanDB.media.archived.length - 1; mediaIndex >= 0; mediaIndex--){
|
for(let mediaIndex = archive.length - 1; mediaIndex >= 0; mediaIndex--){
|
||||||
//Grab the current media record
|
//Grab the current media record
|
||||||
let media = chanDB.media.archived[mediaIndex].rehydrate();
|
let media = archive[mediaIndex].rehydrate();
|
||||||
|
|
||||||
//If the media started within the last 24 hours
|
|
||||||
if(media.startTime > yesterday){
|
|
||||||
//If we're sending out the live remainder during a live stream
|
//If we're sending out the live remainder during a live stream
|
||||||
if(this.liveRemainder != null && media.uuid.toString() == this.liveRemainder.uuid.toString()){
|
if(this.liveRemainder != null && media.uuid.toString() == this.liveRemainder.uuid.toString()){
|
||||||
//Throw out the early end before sending it off, so it looks like it hasn't been cut off yet (smoke n mirrors :P)
|
//Throw out the early end before sending it off, so it looks like it hasn't been cut off yet (smoke n mirrors :P)
|
||||||
|
|
@ -1759,12 +1765,6 @@ class queue{
|
||||||
|
|
||||||
//Add it to the temporary schedule array as if it where part of the actual schedule map
|
//Add it to the temporary schedule array as if it where part of the actual schedule map
|
||||||
schedule.unshift([media.startTime, media]);
|
schedule.unshift([media.startTime, media]);
|
||||||
//Otherwise if it's older
|
|
||||||
}else{
|
|
||||||
//Then we should be done as archived items are added as they are played/end.
|
|
||||||
//No newer items should be beyond this point!
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Concatonate the actual schedule to the items we pulled out of the archive return it
|
//Concatonate the actual schedule to the items we pulled out of the archive return it
|
||||||
|
|
@ -1907,6 +1907,25 @@ class queue{
|
||||||
//Save archivedMedia object to site-wide media archive (gross but performant)
|
//Save archivedMedia object to site-wide media archive (gross but performant)
|
||||||
let archivedDoc = await archivedMediaModel.create(archived);
|
let archivedDoc = await archivedMediaModel.create(archived);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Channel Archive
|
||||||
|
*/
|
||||||
|
async getArchive(startDate){
|
||||||
|
//If we provided a start date
|
||||||
|
if(startDate != null){
|
||||||
|
//Return archived media after start date
|
||||||
|
return await archivedMediaModel.find({
|
||||||
|
channel:this.channel.name,
|
||||||
|
//Prevent mongoose from attempting to sanatize and invalidate our query object, plus I think we can trust an epoch that came from server-side :)
|
||||||
|
startTime: mongoose.trusted({$gt: startDate.getTime()})
|
||||||
|
});
|
||||||
|
//Otherwise
|
||||||
|
}else{
|
||||||
|
//return all archived media
|
||||||
|
return await archivedMediaModel.find({channel:this.channel.name});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = queue;
|
module.exports = queue;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue