caldav-adapter 9.3.0 → 9.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "caldav-adapter",
|
|
3
3
|
"description": "CalDAV server for Node.js and Koa. Modernized and maintained for Forward Email.",
|
|
4
|
-
"version": "9.3.
|
|
4
|
+
"version": "9.3.2",
|
|
5
5
|
"author": "Sanders DeNardi and Forward Email LLC",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Sanders DeNardi <sedenardi@gmail.com> (http://www.sandersdenardi.com/)",
|
|
@@ -16,6 +16,33 @@ const routerCalPut = require('./calendar/put');
|
|
|
16
16
|
const routerCalDelete = require('./calendar/delete');
|
|
17
17
|
const routerScheduling = require('./scheduling');
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Dispatch a method handler and assign its return value to ctx.body.
|
|
21
|
+
* Handlers that return a value (e.g. propfind, report) provide the
|
|
22
|
+
* response body directly. Handlers that manage ctx.status and ctx.body
|
|
23
|
+
* themselves (e.g. put, delete) return undefined; in that case we must
|
|
24
|
+
* NOT overwrite ctx.body, because assigning undefined resets Koa's
|
|
25
|
+
* status to 204.
|
|
26
|
+
*/
|
|
27
|
+
async function dispatchHandler(ctx, handler, ...args) {
|
|
28
|
+
setMultistatusResponse(ctx);
|
|
29
|
+
if (typeof handler.exec === 'function') {
|
|
30
|
+
const result = await handler.exec(ctx, ...args);
|
|
31
|
+
if (result !== undefined) {
|
|
32
|
+
ctx.body = result;
|
|
33
|
+
}
|
|
34
|
+
} else if (typeof handler === 'function') {
|
|
35
|
+
const result = await handler(ctx, ...args);
|
|
36
|
+
if (result !== undefined) {
|
|
37
|
+
ctx.body = result;
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
19
46
|
module.exports = function (options) {
|
|
20
47
|
const log = winston({ ...options, label: 'calendar' });
|
|
21
48
|
const userMethods = {
|
|
@@ -81,17 +108,15 @@ module.exports = function (options) {
|
|
|
81
108
|
}
|
|
82
109
|
|
|
83
110
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
ctx
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
ctx.body = await calMethods[method](ctx, calendar);
|
|
94
|
-
} else {
|
|
111
|
+
// pass calendar object via ctx.state to avoid
|
|
112
|
+
// redundant getCalendar() calls inside handlers
|
|
113
|
+
ctx.state.calendar = calendar;
|
|
114
|
+
const handled = await dispatchHandler(
|
|
115
|
+
ctx,
|
|
116
|
+
calMethods[method],
|
|
117
|
+
calendar
|
|
118
|
+
);
|
|
119
|
+
if (!handled) {
|
|
95
120
|
log.warn(`method handler not found: ${method}`);
|
|
96
121
|
setMissingMethod(ctx);
|
|
97
122
|
ctx.body = notFound(ctx.url);
|
|
@@ -118,13 +143,8 @@ module.exports = function (options) {
|
|
|
118
143
|
}
|
|
119
144
|
|
|
120
145
|
try {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
ctx.body = await userMethods[method].exec(ctx);
|
|
124
|
-
} else if (typeof userMethods[method] === 'function') {
|
|
125
|
-
setMultistatusResponse(ctx);
|
|
126
|
-
ctx.body = await userMethods[method](ctx);
|
|
127
|
-
} else {
|
|
146
|
+
const handled = await dispatchHandler(ctx, userMethods[method]);
|
|
147
|
+
if (!handled) {
|
|
128
148
|
log.warn(`method handler not found: ${method}`);
|
|
129
149
|
setMissingMethod(ctx);
|
|
130
150
|
ctx.body = notFound(ctx.url);
|
|
@@ -6,7 +6,8 @@ const xml = require('../../common/xml');
|
|
|
6
6
|
function parseSupportedComponents(node) {
|
|
7
7
|
const comps = [];
|
|
8
8
|
if (!node.childNodes) return comps;
|
|
9
|
-
for (
|
|
9
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
10
|
+
const comp = node.childNodes[i];
|
|
10
11
|
if (comp.localName !== 'comp') continue;
|
|
11
12
|
const name = comp.getAttribute ? comp.getAttribute('name') : null;
|
|
12
13
|
if (name) comps.push(name.toUpperCase());
|