Skip to content

Commit

Permalink
Merge pull request #9 from aharter/android-etag
Browse files Browse the repository at this point in the history
Fix davx5 missing e-tag error.
  • Loading branch information
sedenardi authored Mar 2, 2021
2 parents 04b6ebd + 402e91b commit 57ed4e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
22 changes: 20 additions & 2 deletions example/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ const bumpSyncToken = function(cal) {
cal.syncToken = parts.slice(0, -1).join('/') + '/' + (parseInt(parts[parts.length - 1]) + 1);
};

const eventFilter = function(start, end, eventStart, eventEnd) {
return (!start || start <= eventEnd) && (!end || end >= eventStart);
};

const recurringEventFilter = function(start, end, event) {
if (!event.recurring) {
return false;
}

const eventStart = event.startDate;
const eventEnd = event.recurring.until ? event.recurring.until : end;
return eventFilter(start, end, eventStart, eventEnd);
};

const singleEventFilter = function(start, end, event) {
return eventFilter(start, end, event.startDate, event.endDate);
};

module.exports.getCalendar = async function({
calendarId,
// principalId,
Expand Down Expand Up @@ -125,8 +143,8 @@ module.exports.getEventsByDate = async function({
return _.filter(data.events, (v) => {
return v.calendarId === calendarId &&
(
(v.startDate >= start && v.endDate <= end) ||
v.weekly
recurringEventFilter(start, end, v) ||
singleEventFilter(start, end, v)
);
});
};
Expand Down
12 changes: 7 additions & 5 deletions src/common/xBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ type XmlElement = {
[tag: string]: any;
};

const nsMap = mapKeys(namespaces, (v, k) => {
return `@xmlns:${k}`;
});
const nsMap = function() {
return mapKeys(namespaces, (v, k) => {
return `@xmlns:${k}`;
});
};

export const buildTag = function(namespaceURI: string, localName: string) {
return `${nsLookup[namespaceURI]}:${localName}`;
Expand All @@ -24,7 +26,7 @@ export const build = function(obj: XmlElement) {

export const multistatus = function(responses?: any, other?: object): XmlElement {
const res = {
[buildTag('DAV:', 'multistatus')]: nsMap
[buildTag('DAV:', 'multistatus')]: nsMap()
};
if (responses?.length) {
res[buildTag('DAV:', 'multistatus')][buildTag('DAV:', 'response')] = responses;
Expand Down Expand Up @@ -71,7 +73,7 @@ export const preconditionFail = function(url: string, reason: string) {
const res = {
'D:error': Object.assign({
[buildTag('urn:ietf:params:xml:ns:caldav', reason)]: url
}, nsMap)
}, nsMap())
};
return build(res);
};
2 changes: 1 addition & 1 deletion src/common/xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const get = function<T extends Node>(path: string, doc: Document) {
};

export const getWithChildren = function(path: string, doc: Document) {
const propNode = get<Element>('/D:propfind/D:prop', doc);
const propNode = get<Element>(path, doc);
const children = propNode[0] ? (Array.from(propNode[0].childNodes) as Element[]) : [];
return { propNode, children };
};

0 comments on commit 57ed4e8

Please sign in to comment.