forked from SoulOfNoob/MMM-NextCloud-Tasks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebDavHelper.js
executable file
·37 lines (32 loc) · 1.01 KB
/
webDavHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* eslint-disable indent */
const { createClient } = require("webdav");
const ical = require('node-ical');
const transformer = require("./transformer");
function initWebDav(config) {
return client = createClient(config.listUrl, config.webDavAuth);
}
function parseList(icsStrings) {
let elements = [];
for (const icsStr of icsStrings) {
const icsObj = ical.sync.parseICS(icsStr);
Object.values(icsObj).forEach(element => {
if (element.type === 'VTODO') elements.push(element);
});
}
return elements;
}
async function fetchList(config) {
const client = initWebDav(config);
const directoryItems = await client.getDirectoryContents("/");
let icsStrings = [];
for (const element of directoryItems) {
const icsStr = await client.getFileContents(element.filename, { format: "text" });
//console.log(icsStr);
icsStrings.push(icsStr);
}
return icsStrings;
}
module.exports = {
parseList: parseList,
fetchList: fetchList
};