-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
85 lines (69 loc) · 2.54 KB
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const sppull = require('sppull').sppull
const readYaml = require('read-yaml')
const rmdirRecursiveSync = require('rmdir-recursive').sync
const Cpass = require('cpass').Cpass
const cpass = new Cpass()
const email = require("emailjs/email");
function readConfigs (fn) {
return readYaml.sync(fn)
}
const configsFn = './configs/secured_config.yaml'
const configs = readConfigs(configsFn)
const emailConfigFn = './configs/email_config_server.yaml'
const emailConfigs = readConfigs(emailConfigFn)
// remove all files in the directory before downloading
const directory = configs.dlRootFolder
try {
rmdirRecursiveSync(directory)
console.log(directory + ' removed')
} catch (err) {
console.log(directory + ' cant removed with status ' + err)
}
// uses cpass to decode password
const context = {
siteUrl: configs.siteUrl,
creds: {
username: configs.username,
password: cpass.decode(configs.password)
}
}
console.log()
console.log(configs.siteUrl)
console.log(cpass.decode(configs.password))
console.log()
let emailServer = email.server.connect({
host: emailConfigs.server_addr,
port: emailConfigs.server_port,
});
const emailServerFailureMsg = {
// text: emailConfigs.etl_failure_msg,
from: emailConfigs.etl_sender_addr,
to: emailConfigs.etl_recipients,
subject: emailConfigs.etl_failure_subject,
//attachment: emailConfigs.etl_failure_msg}]
}
const options = {
// root remote folder
spRootFolder: configs.spRootFolder,
// root local download folder
dlRootFolder: configs.dlRootFolder,
// don't search for sub-directories inside the root folder
recursive: false
}
/*
* All files will be downloaded from http://some.sharepoint.com/subsite/Shared%20Documents/blah folder
* to __dirname + /Downloads/ folder.
* If you set recursive to true, folders structure will remain original as it is in SharePoint's target folder.
*/
sppull(context, options)
.then(function (downloadResults) {
console.log('Files are downloaded')
console.log('For more, please check the results', JSON.stringify(downloadResults))
})
.catch(function (err) {
console.log('Core error has happened', err)
console.log(err)
emailServerFailureMsg.attachment = [{data:"<html><h2>" + emailConfigs.etl_failure_msg + "</h2><br><h3> See the server error message below </h3>" + JSON.stringify(err) + "</html>", alternative:true}]
// send the message and get a callback with an error or details of the message that was sent
emailServer.send( emailServerFailureMsg, function(err, message) { console.log(err || message); });
})