Updated public channel list API endpoint to provide next 90 minutes of scheduled media
This commit is contained in:
parent
340dfdf4ac
commit
0291904534
3 changed files with 27 additions and 5 deletions
|
|
@ -284,9 +284,10 @@ channelSchema.statics.register = async function(channelObj, ownerObj){
|
|||
/**
|
||||
* Generates Network-Friendly Browser-Digestable list of channels
|
||||
* @param {Boolean} includeHidden - Whether or not to include hidden channels within the list
|
||||
* @param {Date} endDate - Limits amount of scheduled items sent, defaults to 90 minutes
|
||||
* @returns {Array} List of Network-Friendly Browser-Digestable Objects representing channels on the server
|
||||
*/
|
||||
channelSchema.statics.getChannelList = async function(includeHidden = false){
|
||||
channelSchema.statics.getChannelList = async function(includeHidden = false, endDate = new Date(Date.now() + (1000 * 60 * 90))){
|
||||
const chanDB = await this.find({});
|
||||
var chanGuide = [];
|
||||
|
||||
|
|
@ -294,12 +295,32 @@ channelSchema.statics.getChannelList = async function(includeHidden = false){
|
|||
chanDB.forEach((channel) => {
|
||||
//For each channel, push an object with only the information we need to the channel guide
|
||||
if(!channel.settings.hidden || includeHidden){
|
||||
chanGuide.push({
|
||||
//Create freeze-dried channel entry object (just add bong water)
|
||||
const entry = {
|
||||
id: channel.id,
|
||||
name: channel.name,
|
||||
description: channel.description,
|
||||
thumbnail: channel.thumbnail
|
||||
});
|
||||
thumbnail: channel.thumbnail,
|
||||
schedule: []
|
||||
}
|
||||
|
||||
//If we're currently playing something
|
||||
if(channel.media.nowPlaying != null){
|
||||
//Toss the currently playing item on
|
||||
entry.schedule.push(channel.media.nowPlaying);
|
||||
}
|
||||
|
||||
//For every piece of scehduled media for this channel
|
||||
for(const media of channel.media.scheduled){
|
||||
//If it starts before our cut-off
|
||||
if(endDate.getTime() > media.startTime){
|
||||
//Add that shit, son!
|
||||
entry.schedule.push(media);
|
||||
}
|
||||
}
|
||||
|
||||
//add the channel entry to our return array
|
||||
chanGuide.push(entry);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue