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
|
|
@ -21,6 +21,7 @@ const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils');
|
|||
//api account functions
|
||||
module.exports.get = async function(req, res){
|
||||
try{
|
||||
//We pull this from the DB insteada activeChannels because we want to list channels that arent active after server restarts
|
||||
const chanGuide = await channelModel.getChannelList();
|
||||
|
||||
res.status(200);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ router.post('/thumbnail', channelValidator.thumbnail(), thumbnailController.post
|
|||
router.get('/description', descriptionController.get);
|
||||
router.post('/description', channelValidator.description(), descriptionController.post);
|
||||
//list
|
||||
router.get('/list', channelModel.reqPermCheck("manageChannel"), listController.get);
|
||||
router.get('/list', listController.get);
|
||||
//settings
|
||||
router.get('/settings', channelModel.reqPermCheck("manageChannel"), settingsController.get);
|
||||
router.post('/settings', channelModel.reqPermCheck("changeSettings"), channelValidator.settingsMap(), settingsController.post);
|
||||
|
|
|
|||
|
|
@ -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