1
0
Fork 0

parse calendar data

This commit is contained in:
Ryan Mwangi 2024-10-24 15:30:01 +03:00
parent d2d0f7fd1e
commit 418fea84b9
1 changed files with 23 additions and 0 deletions

View File

@ -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) {