From c5b6fbaaaf90d1d149471d3a4e4451cefd26938d Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Wed, 2 Oct 2024 02:08:49 +0300 Subject: [PATCH] fetch calendar data from urls --- server.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 6ec690d..c216cfc 100644 --- a/server.js +++ b/server.js @@ -22,8 +22,21 @@ app.post('/merge', async (req, res) => { return res.status(400).json({ error: 'Invalid input' }); } // Fetch calendar data from URLs - const cal1Data = await axios.get(cal1Url); - const cal2Data = await axios.get(cal2Url); + const promises = calendars.map((calendar) => { + return axios.get(calendar.url) + .then((response) => { + return { + data: response.data, + prefix: calendar.prefix, + }; + }) + .catch((error) => { + console.error(error); + return null; + }); + }); + + const results = await Promise.all(promises); // Parse calendar data const cal1 = ical.parseICS(cal1Data.data);