Compare commits

...

3 Commits

1 changed files with 21 additions and 3 deletions

View File

@ -114,16 +114,34 @@ app.get('/calendar/:id', (req, res) => {
});
//function to save CalendarData to calendars.json
function saveCalendarData(calendarId, calendars) {
function saveCalendarData(calendarId, linkGroupName, calendars) {
let calendarsData = { mergedCalendars: [] };
if (fs.existsSync(CALENDARS_FILE)) {
calendarsData = JSON.parse(fs.readFileSync(CALENDARS_FILE, 'utf8'));
try {
const fileContent = fs.readFileSync(CALENDARS_FILE, 'utf8');
if (fileContent) {
calendarsData = JSON.parse(fileContent);
}
} catch (error) {
console.error('Error reading calendars file:', error);
}
}
// Ensure mergedCalendars array exists
if (!calendarsData.mergedCalendars) {
calendarsData.mergedCalendars = [];
}
calendarsData.mergedCalendars.push({
id: calendarId,
linkGroupName: linkGroupName,
calendars: calendars
});
fs.writeFileSync(CALENDARS_FILE, JSON.stringify(calendarsData, null, 2));
try {
fs.writeFileSync(CALENDARS_FILE, JSON.stringify(calendarsData, null, 2));
} catch (error) {
console.error('Error writing to calendars file:', error);
}
}
// Function to update the merged calendar