Compare commits

..

No commits in common. "fe35fd36650c7fb4231c2559457b85749b86d9db" and "896738a1231eda0b66fa97f7e3501b022f9a7af8" have entirely different histories.

1 changed files with 31 additions and 18 deletions

View File

@ -167,27 +167,28 @@ async function updateMergedCalendar(){
if (!calendarsData || !calendarsData.linkGroups) {
throw new Error('Invalid calendars data structure');
}
console.log(calendarsData);
// Fetch calendar data for each link group
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 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;
});
}));
});
const results = await Promise.all(promises);
// Filter out any failed requests
const validResults = results.filter((result) => result !== null);
const validResults = results.flat().filter((result) => result !== null);
// Parse calendar data
const mergedCal = [];
@ -228,12 +229,17 @@ 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);
}
@ -245,6 +251,13 @@ 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, () => {