Compare commits

..

3 Commits

1 changed files with 18 additions and 31 deletions

View File

@ -167,28 +167,27 @@ async function updateMergedCalendar(){
if (!calendarsData || !calendarsData.linkGroups) {
throw new Error('Invalid calendars data structure');
}
console.log(calendarsData);
// Fetch calendar data for each link group
const promises = calendarsData.linkGroups.map((linkGroup) => {
return Promise.all(linkGroup.links.map((link) => {
return axios.get(link.url)
.then((response) => {
return {
data: response.data,
prefix: link.prefix,
override: link.override,
};
})
.catch((error) => {
console.error(error);
return null;
});
}));
});
for (const mergedCalendar of calendarsData.mergedCalendars) {
const promises = mergedCalendar.calendars.map((calendar) => {
return axios.get(calendar.url)
.then((response) => {
return {
data: response.data,
prefix: calendar.prefix,
override: calendar.override,
};
})
.catch((error) => {
console.error(error);
return null;
});
});
const results = await Promise.all(promises);
// Filter out any failed requests
const validResults = results.flat().filter((result) => result !== null);
const validResults = results.filter((result) => result !== null);
// Parse calendar data
const mergedCal = [];
@ -229,17 +228,12 @@ END:VEVENT
});
icalString += `END:VCALENDAR`;
fs.writeFileSync(filename, icalString);
// Generate a unique URL for the merged calendar
const mergedCalendarUrl = `http://localhost:3000/${filename}`;
// Store the merged calendar URL in a file
fs.writeFileSync(`${MERGED_CALENDARS_DIR}/${filename}`, icalString);
console.log(`Merged calendar updated: ${mergedCalendarUrl}`);
}
} catch (error) {
console.error(error);
}
@ -251,13 +245,6 @@ cron.schedule('*/3 * * * *', () => {
updateMergedCalendar();
});
// serve updated merged calendar to user
app.get('/merged-calendar', (req, res) => {
const mergedCalendarUrlFile = 'merged_calendar_url.txt';
const mergedCalendarUrl = fs.readFileSync(mergedCalendarUrlFile, 'utf8');
res.redirect(mergedCalendarUrl);
});
// Start the server
const port = 3000;
app.listen(port, () => {