From c264c6b84254dc279a2ae37fd960b75e1da381d0 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Mon, 4 Nov 2024 15:23:21 +0300 Subject: [PATCH] parse calendar data in calendar/:name endpoint with ICAL --- server.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server.js b/server.js index b80df59..7db8827 100644 --- a/server.js +++ b/server.js @@ -175,6 +175,17 @@ app.get('/calendar/:name', async (req, res) => { // Parse calendar data validResults.forEach((result) => { + const parsed = ICAL.parse(result.data); + const component = new ICAL.Component(parsed); + const events = component.getAllSubcomponents('vevent'); + + events.forEach((event) => { + const vevent = new ICAL.Event(event); + const start = vevent.startDate.toJSDate(); + const end = vevent.endDate.toJSDate(); + const summary = result.override ? result.prefix : `${result.prefix} ${vevent.summary}`; + }); + const parsedCalendar = ical.parseICS(result.data); Object.keys(parsedCalendar).forEach((key) => { const event = parsedCalendar[key];