From 8cdeba3d93592d9b2f3aa1572f1fbb99f7a450f1 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Sat, 19 Oct 2024 02:21:20 +0300 Subject: [PATCH] edit updateMergedCalendar function --- server.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 30553e8..9a1a93e 100644 --- a/server.js +++ b/server.js @@ -160,8 +160,7 @@ app.get('/:filename', (req, res) => { async function updateMergedCalendar(){ try { // Load calendars data from calendars.json file - const calendarsFile = 'calendars.json'; - const calendarsData = JSON.parse(fs.readFileSync(calendarsFile, 'utf8')); + const calendarsData = JSON.parse(fs.readFileSync(CALENDARS_FILE, 'utf8')); // Check if calendarsData is defined and has the expected structure if (!calendarsData || !calendarsData.linkGroups) { @@ -213,7 +212,7 @@ async function updateMergedCalendar(){ }); // Save merged calendar to file - const filename = `merged-${Date.now()}.ics`; + const filename = `${mergedCalendar.id}.ics`; let icalString = `BEGIN:VCALENDAR VERSION:2.0 CALSCALE:GREGORIAN @@ -235,7 +234,7 @@ END:VEVENT const mergedCalendarUrl = `http://localhost:3000/${filename}`; // Store the merged calendar URL in a file - fs.writeFileSync('merged_calendar_url.txt', mergedCalendarUrl); + fs.writeFileSync(`${MERGED_CALENDARS_DIR}/${filename}`, icalString); console.log(`Merged calendar updated: ${mergedCalendarUrl}`);