parse calendar data using ical-generator
This commit is contained in:
parent
4310d3f395
commit
8927cc1cd3
30
server.js
30
server.js
|
@ -142,24 +142,20 @@ app.get('/calendar/:name', async (req, res) => {
|
||||||
const calendar = icalGenerator({ name: calendarName });
|
const calendar = icalGenerator({ name: calendarName });
|
||||||
|
|
||||||
// Parse calendar data
|
// Parse calendar data
|
||||||
const mergedCal = [];
|
|
||||||
validResults.forEach((result) => {
|
validResults.forEach((result) => {
|
||||||
const calendar = ical.parseICS(result.data);
|
const parsedCalendar = ical.parseICS(result.data);
|
||||||
Object.keys(calendar).forEach((key) => {
|
Object.keys(parsedCalendar).forEach((key) => {
|
||||||
const event = calendar[key];
|
const event = parsedCalendar[key];
|
||||||
if (result.override) {
|
const start = new Date(event.start);
|
||||||
mergedCal.push({
|
const end = new Date(event.end);
|
||||||
start: event.start,
|
const summary = result.override ? result.prefix : `${result.prefix} ${event.summary}`;
|
||||||
end: event.end,
|
|
||||||
summary: result.prefix,
|
// Add event to the calendar
|
||||||
});
|
calendar.createEvent({
|
||||||
} else {
|
start: start,
|
||||||
mergedCal.push({
|
end: end,
|
||||||
start: event.start,
|
summary: summary,
|
||||||
end: event.end,
|
});
|
||||||
summary: `${result.prefix} ${event.summary}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue