1
0
Fork 0

fetch calendar data from urls

This commit is contained in:
Ryan Mwangi 2024-10-02 02:08:49 +03:00
parent 89bd4582d1
commit c5b6fbaaaf
1 changed files with 15 additions and 2 deletions

View File

@ -22,8 +22,21 @@ app.post('/merge', async (req, res) => {
return res.status(400).json({ error: 'Invalid input' }); return res.status(400).json({ error: 'Invalid input' });
} }
// Fetch calendar data from URLs // Fetch calendar data from URLs
const cal1Data = await axios.get(cal1Url); const promises = calendars.map((calendar) => {
const cal2Data = await axios.get(cal2Url); 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 // Parse calendar data
const cal1 = ical.parseICS(cal1Data.data); const cal1 = ical.parseICS(cal1Data.data);