caldav-adapter 8.2.8 → 8.2.9
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 +1 -1
- package/routes/calendar/calendar/get.js +69 -10
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": "8.2.
|
|
4
|
+
"version": "8.2.9",
|
|
5
5
|
"author": "Sanders DeNardi and Forward Email LLC",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Sanders DeNardi <sedenardi@gmail.com> (http://www.sandersdenardi.com/)",
|
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
const { setMissingMethod } = require('../../../common/response');
|
|
2
2
|
const winston = require('../../../common/winston');
|
|
3
|
+
const {
|
|
4
|
+
response,
|
|
5
|
+
status,
|
|
6
|
+
build,
|
|
7
|
+
multistatus
|
|
8
|
+
} = require('../../../common/x-build');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Encode special characters for XML content to prevent parsing errors
|
|
12
|
+
* @param {string} str - String to encode
|
|
13
|
+
* @returns {string} - XML-safe encoded string
|
|
14
|
+
*/
|
|
15
|
+
function encodeXMLEntities(str) {
|
|
16
|
+
if (typeof str !== 'string') {
|
|
17
|
+
return str;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return str
|
|
21
|
+
.replaceAll('&', '&') // Must be first to avoid double-encoding
|
|
22
|
+
.replaceAll('<', '<')
|
|
23
|
+
.replaceAll('>', '>')
|
|
24
|
+
.replaceAll('"', '"')
|
|
25
|
+
.replaceAll("'", ''');
|
|
26
|
+
}
|
|
3
27
|
|
|
4
28
|
module.exports = function (options) {
|
|
5
29
|
const log = winston({ ...options, label: 'calendar/get' });
|
|
@@ -15,11 +39,29 @@ module.exports = function (options) {
|
|
|
15
39
|
|
|
16
40
|
const ics = await options.data.buildICS(ctx, events, calendar);
|
|
17
41
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
42
|
+
if (
|
|
43
|
+
ctx.accepts('text/calendar') ||
|
|
44
|
+
ctx.accepts('application/ics') ||
|
|
45
|
+
ctx.accepts('text/x-vcalendar') ||
|
|
46
|
+
ctx.accepts('application/octet-stream')
|
|
47
|
+
) {
|
|
48
|
+
ctx.status = 200;
|
|
49
|
+
ctx.remove('DAV');
|
|
50
|
+
ctx.set('Content-Type', 'text/calendar; charset=utf-8');
|
|
51
|
+
ctx.set('ETag', options.data.getETag(ctx, calendar));
|
|
52
|
+
return ics;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// xml
|
|
56
|
+
const responseObj = response(ctx.url, status[200], [
|
|
57
|
+
{
|
|
58
|
+
'D:getetag': options.data.getETag(ctx, calendar)
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
'CAL:calendar-data': encodeXMLEntities(ics)
|
|
62
|
+
}
|
|
63
|
+
]);
|
|
64
|
+
return build(multistatus([responseObj]));
|
|
23
65
|
}
|
|
24
66
|
|
|
25
67
|
const event = await options.data.getEvent(ctx, {
|
|
@@ -37,11 +79,28 @@ module.exports = function (options) {
|
|
|
37
79
|
|
|
38
80
|
const ics = await options.data.buildICS(ctx, event, calendar);
|
|
39
81
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
82
|
+
if (
|
|
83
|
+
ctx.accepts('text/calendar') ||
|
|
84
|
+
ctx.accepts('application/ics') ||
|
|
85
|
+
ctx.accepts('text/x-vcalendar') ||
|
|
86
|
+
ctx.accepts('application/octet-stream')
|
|
87
|
+
) {
|
|
88
|
+
ctx.status = 200;
|
|
89
|
+
ctx.remove('DAV');
|
|
90
|
+
ctx.set('Content-Type', 'text/calendar; charset=utf-8');
|
|
91
|
+
ctx.set('ETag', options.data.getETag(ctx, calendar));
|
|
92
|
+
return ics;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const responseObj = response(ctx.url, status[200], [
|
|
96
|
+
{
|
|
97
|
+
'D:getetag': options.data.getETag(ctx, calendar)
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
'CAL:calendar-data': encodeXMLEntities(ics)
|
|
101
|
+
}
|
|
102
|
+
]);
|
|
103
|
+
return build(multistatus([responseObj]));
|
|
45
104
|
};
|
|
46
105
|
|
|
47
106
|
return {
|