Fix calendar: expand recurring events, strip XML-encoded carriage returns
This commit is contained in:
parent
27d8f16313
commit
f896561771
1 changed files with 10 additions and 3 deletions
13
bin/calendar
13
bin/calendar
|
|
@ -31,9 +31,14 @@ function caldavRequest(startDate, endDate) {
|
|||
const url = new URL(`/remote.php/dav/calendars/${USER}/${CALENDAR}/`, BASE_URL);
|
||||
const auth = Buffer.from(`${USER}:${PASS}`).toString('base64');
|
||||
|
||||
// Use calendar-multiget with expand to get expanded recurrences
|
||||
const body = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop><c:calendar-data/></d:prop>
|
||||
<d:prop>
|
||||
<c:calendar-data>
|
||||
<c:expand start="${startDate}" end="${endDate}"/>
|
||||
</c:calendar-data>
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR">
|
||||
<c:comp-filter name="VEVENT">
|
||||
|
|
@ -68,15 +73,17 @@ function caldavRequest(startDate, endDate) {
|
|||
|
||||
function parseEvents(xmlData) {
|
||||
const events = [];
|
||||
// Strip carriage returns (raw and XML-encoded) from entire response
|
||||
xmlData = xmlData.replace(/\r/g, '').replace(/ /g, '');
|
||||
const eventBlocks = xmlData.split('BEGIN:VEVENT');
|
||||
|
||||
for (let i = 1; i < eventBlocks.length; i++) {
|
||||
const block = eventBlocks[i].split('END:VEVENT')[0];
|
||||
const get = (key) => {
|
||||
// Handle both folded and unfolded lines
|
||||
// Handle both folded and unfolded lines, strip \r
|
||||
const regex = new RegExp(`${key}[^:]*:(.+?)(?:\\r?\\n(?! ))`, 's');
|
||||
const m = block.match(regex);
|
||||
return m ? m[1].replace(/\r?\n\s/g, '').trim() : null;
|
||||
return m ? m[1].replace(/\r?\n\s/g, '').replace(/\r/g, '').trim() : null;
|
||||
};
|
||||
|
||||
const summary = get('SUMMARY');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue