Compare commits

...

3 Commits

2 changed files with 14 additions and 3 deletions

0
merged_calendar_url.txt Normal file
View File

View File

@ -168,10 +168,15 @@ END:VEVENT
`; `;
}); });
icalString += `END:VCALENDAR`; icalString += `END:VCALENDAR`;
fs.writeFileSync(filename, icalString); fs.writeFileSync(filename, icalString);
// Generate a unique URL for the merged calendar // Generate a unique URL for the merged calendar
const mergedCalendarUrl = `${req.protocol}://${req.get('host')}/${filename}`; const mergedCalendarUrl = `http://localhost:3000/${filename}`;
// Store the merged calendar URL in a file
fs.writeFileSync(mergedCalendarUrlFile, mergedCalendarUrl);
console.log(`Merged calendar updated: ${mergedCalendarUrl}`); console.log(`Merged calendar updated: ${mergedCalendarUrl}`);
@ -180,13 +185,19 @@ END:VEVENT
} }
} }
// Schedule a cron job to update the merged calendar every hour // Schedule a cron job to update the merged calendar every hour
cron.schedule('0 * * * *', () => { cron.schedule('0 * * * *', () => {
console.log('Updating merged calendar...'); console.log('Updating merged calendar...');
updateMergedCalendar(); 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 // Start the server
const port = 3000; const port = 3000;
app.listen(port, () => { app.listen(port, () => {