Updated public channel list API endpoint to provide next 90 minutes of scheduled media

This commit is contained in:
rainbow napkin 2026-11-09 02:44:06 -05:00
parent 340dfdf4ac
commit 0291904534
3 changed files with 27 additions and 5 deletions

View file

@ -21,6 +21,7 @@ const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils');
//api account functions //api account functions
module.exports.get = async function(req, res){ module.exports.get = async function(req, res){
try{ 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(); const chanGuide = await channelModel.getChannelList();
res.status(200); res.status(200);

View file

@ -66,7 +66,7 @@ router.post('/thumbnail', channelValidator.thumbnail(), thumbnailController.post
router.get('/description', descriptionController.get); router.get('/description', descriptionController.get);
router.post('/description', channelValidator.description(), descriptionController.post); router.post('/description', channelValidator.description(), descriptionController.post);
//list //list
router.get('/list', channelModel.reqPermCheck("manageChannel"), listController.get); router.get('/list', listController.get);
//settings //settings
router.get('/settings', channelModel.reqPermCheck("manageChannel"), settingsController.get); router.get('/settings', channelModel.reqPermCheck("manageChannel"), settingsController.get);
router.post('/settings', channelModel.reqPermCheck("changeSettings"), channelValidator.settingsMap(), settingsController.post); router.post('/settings', channelModel.reqPermCheck("changeSettings"), channelValidator.settingsMap(), settingsController.post);

View file

@ -284,9 +284,10 @@ channelSchema.statics.register = async function(channelObj, ownerObj){
/** /**
* Generates Network-Friendly Browser-Digestable list of channels * Generates Network-Friendly Browser-Digestable list of channels
* @param {Boolean} includeHidden - Whether or not to include hidden channels within the list * @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 * @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({}); const chanDB = await this.find({});
var chanGuide = []; var chanGuide = [];
@ -294,12 +295,32 @@ channelSchema.statics.getChannelList = async function(includeHidden = false){
chanDB.forEach((channel) => { chanDB.forEach((channel) => {
//For each channel, push an object with only the information we need to the channel guide //For each channel, push an object with only the information we need to the channel guide
if(!channel.settings.hidden || includeHidden){ if(!channel.settings.hidden || includeHidden){
chanGuide.push({ //Create freeze-dried channel entry object (just add bong water)
const entry = {
id: channel.id, id: channel.id,
name: channel.name, name: channel.name,
description: channel.description, 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);
} }
}); });