From ae0d41dca45554f9dc2a2bf9c8982755907b9815 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Sat, 19 Oct 2024 17:36:27 +0300 Subject: [PATCH] remove unused code for saving file in calendars.json --- server.js | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/server.js b/server.js index 222f258..26889ea 100644 --- a/server.js +++ b/server.js @@ -91,40 +91,11 @@ END:VEVENT }); icalString += `END:VCALENDAR`; fs.writeFileSync(`${MERGED_CALENDARS_DIR}/${filename}`, icalString); - - - // Generate URL for the merged calendar - const mergedCalendarUrl = `${req.protocol}://${req.get('host')}/calendar/${calendarId}`; - + // Save the user input and generated ID in calendars.json file saveCalendarData(calendarId, calendars); - // Save the user input in a calendars.json file - const calendarsFile = 'calendars.json'; - let calendarsData = {}; - try { - calendarsData = JSON.parse(fs.readFileSync(calendarsFile, 'utf8')); - } catch (error) { - console.error(error); - } - calendars.forEach((calendar) => { - let linkGroup = calendarsData.linkGroups.find((group) => group.name === calendar.linkGroupName); - if (!linkGroup) { - linkGroup = { - name: calendar.linkGroupName, - links: [] - }; - calendarsData.linkGroups.push(linkGroup); - } - linkGroup.links.push({ - url: calendar.url, - prefix: calendar.prefix, - overrideSummary: calendar.override - }); - }); - fs.writeFileSync(calendarsFile, JSON.stringify(calendarsData, null, 2)); - - res.json({ url: mergedCalendarUrl }); + res.json({ url: `${req.protocol}://${req.get('host')}/calendar/${calendarId}` }); } catch (error) { console.error(error); res.status(500).json({ error: 'Failed to merge calendars' });