forked from ryanmwangi/CalMerger
parse calendar data
This commit is contained in:
parent
d2d0f7fd1e
commit
418fea84b9
23
server.js
23
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) {
|
||||
|
|
Loading…
Reference in New Issue