From 418fea84b9dcafeb2dea7886cafe326180b4cb38 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Thu, 24 Oct 2024 15:30:01 +0300 Subject: [PATCH] parse calendar data --- server.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server.js b/server.js index 1e6a4ce..ebb8c01 100644 --- a/server.js +++ b/server.js @@ -145,6 +145,29 @@ app.get('/calendar/:name', async (req, res) => { const results = await Promise.all(promises); // Filter out any failed requests const validResults = results.filter((result) => result !== null); + + // Parse calendar data + const mergedCal = []; + validResults.forEach((result) => { + const calendar = ical.parseICS(result.data); + Object.keys(calendar).forEach((key) => { + const event = calendar[key]; + if (result.override) { + mergedCal.push({ + start: event.start, + end: event.end, + summary: result.prefix, + }); + } else { + mergedCal.push({ + start: event.start, + end: event.end, + summary: `${result.prefix} ${event.summary}`, + }); + } + }); + }); + } } } catch (error) {