From 0e7e3e7804bc45b406d12f79d03591fc819db2a0 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Sat, 19 Oct 2024 18:32:43 +0300 Subject: [PATCH] restructure calendars.json --- calendars.json | 22 +++++++++++++--------- server.js | 16 ++++++++++------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/calendars.json b/calendars.json index 8d5d05e..87510c4 100644 --- a/calendars.json +++ b/calendars.json @@ -1,32 +1,36 @@ { - "linkGroups": [ + "mergedCalendars": [ { - "name": "Group 1", - "links": [ + "id": "uniqueId1", + "calendars": [ { + "linkGroupName": "Group 1", "url": "https://example.com/calendar1.ics", "prefix": "Calendar 1", - "overrideSummary": false + "override": false }, { + "linkGroupName": "Group 1", "url": "https://example.com/calendar2.ics", "prefix": "Calendar 2", - "overrideSummary": true + "override": true } ] }, { - "name": "Group 2", - "links": [ + "id": "uniqueId2", + "calendars": [ { + "linkGroupName": "Group 2", "url": "https://example.com/calendar3.ics", "prefix": "Calendar 3", - "overrideSummary": false + "override": false }, { + "linkGroupName": "Group 2", "url": "https://example.com/calendar4.ics", "prefix": "Calendar 4", - "overrideSummary": true + "override": true } ] } diff --git a/server.js b/server.js index 921268e..01adbb5 100644 --- a/server.js +++ b/server.js @@ -16,6 +16,11 @@ if (!fs.existsSync(MERGED_CALENDARS_DIR)) { fs.mkdirSync(MERGED_CALENDARS_DIR); } +app.get('/script.js', (req, res) => { + res.setHeader('Content-Type', 'application/javascript'); + res.sendFile('script.js', { root: '.' }); +}); + app.get('/', (req, res) => { res.sendFile('index.html', { root: '.' }); }); @@ -73,7 +78,6 @@ app.post('/merge', async (req, res) => { }); }); - // Save merged calendar to file with unique identifier const filename = `${calendarId}.ics`; let icalString = `BEGIN:VCALENDAR @@ -84,14 +88,14 @@ METHOD:PUBLISH mergedCal.forEach((event) => { icalString += `BEGIN:VEVENT DTSTART;VALUE=DATE:${event.start.toISOString().split('T')[0].replace(/-/g, '')} -DTEND;VALUE=DATE:${event.end.toISOString().split('T')[0].replace(/-/g, '')} +DTEND;VALUE=DATE:${ event.end.toISOString().split('T')[0].replace(/-/g, '')} SUMMARY:${event.summary} END:VEVENT `; }); icalString += `END:VCALENDAR`; fs.writeFileSync(`${MERGED_CALENDARS_DIR}/${filename}`, icalString); - + // Save the user input and generated ID in calendars.json file saveCalendarData(calendarId, calendars); @@ -191,7 +195,7 @@ END:VEVENT // Store the merged calendar URL in a file fs.writeFileSync(`${MERGED_CALENDARS_DIR}/${filename}`, icalString); - console.log(`Merged calendar updated: ${mergedCalendarUrl}`); + console.log(`Merged calendar updated: ${mergedCalendar.id}`); } } catch (error) { @@ -200,7 +204,7 @@ END:VEVENT } // Schedule a cron job to update the merged calendar every hour -cron.schedule('*/3 * * * *', () => { +cron.schedule('1 * * * *', () => { console.log('Updating merged calendar...'); updateMergedCalendars(); }); @@ -209,4 +213,4 @@ cron.schedule('*/3 * * * *', () => { const port = 3000; app.listen(port, () => { console.log(`Server started on port ${port}`); -}); +}); \ No newline at end of file