From d6c1ff448234c1c40b1392f6e495f433f58cce25 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 15 Jan 2022 18:23:00 +0300 Subject: [PATCH] Update update-api.js --- scripts/commands/update-api.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/commands/update-api.js b/scripts/commands/update-api.js index 78a4d11b..3bc65167 100644 --- a/scripts/commands/update-api.js +++ b/scripts/commands/update-api.js @@ -15,14 +15,22 @@ async function generateChannelsJson() { const channels = await loadChannels() - await file.create(`${API_DIR}/channels.json`, JSON.stringify(channels)) + const channelsPath = `${API_DIR}/channels.json` + logger.info(`Saving to "${channelsPath}"...`) + await file.create(channelsPath, JSON.stringify(channels)) + + logger.info(`Done`) } async function loadChannels() { - let items = await db.channels.find({}).sort({ xmltv_id: 1 }) + logger.info('Loading channels from database...') - let output = {} - items.forEach(item => { + await db.channels.load() + + const items = await db.channels.find({}).sort({ xmltv_id: 1 }) + + const output = {} + for (const item of items) { if (!output[item.xmltv_id]) { output[item.xmltv_id] = { id: item.xmltv_id, @@ -40,7 +48,7 @@ async function loadChannels() { output[item.xmltv_id].guides.push( `https://iptv-org.github.io/epg/guides/${item.gid}/${item.site}.epg.xml` ) - }) + } return Object.values(output) }