-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSynologyAPI.js
117 lines (97 loc) · 2.8 KB
/
SynologyAPI.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const Utils = require("./Modules/Utils/GenericUtils.js");
const colors = require('colors');
const AuthClass = require("./Modules/Auth/auth.js")
const DownloadStationClass = require("./Modules/DownloadStation/ds.js")
// Constructor
/**
* Synology Settings
* @param {String} protocol / HTTP by default
* @param {String} address
* @param {String} port / 5000 by default
* @param {String} username
* @param {String} password
* @param {Boolean} debug / False by default
* @return {Boolean} / If true, everything is ok
*/
function SynologyAPI(protocol, address, port, username, password, debug) {
this.utils = new Utils();
this.server = {
protocol: "",
address: "",
port: "",
username: "",
password: "",
debug: false,
token: "",
success: false,
message: ""
};
// Debug verification
if (debug == true) {
this.server.debug = debug;
};
//Protocol verification
if (protocol == "HTTP" || protocol == "HTTPS") {
if (this.server.debug) {
console.log("Protocol : " + protocol)
}
this.server.protocol = protocol
} else {
if (this.server.debug) {
console.log("Protocol : Force to HTTP")
}
this.server.protocol = "HTTP"
}
if (this.server.debug) {
console.log("Address : " + address)
}
this.server.address = address
//Port verification
if (port) {
if (this.server.debug) {
console.log("Port : " + port)
}
this.server.port = port
} else {
if (this.server.debug) {
console.log("Port : Force to 5000")
}
}
//Username verification
if (username) {
if (this.server.debug) {
console.log("Username : " + username)
}
this.server.username = username
} else {
if (this.server.debug) {
console.log("Username : Is empty".red)
}
this.server.success = false;
this.server.message = "You need to set a username"
}
//Password verification
if (password) {
if (this.server.debug) {
console.log("Password : " + "Only you knows your password :-)")
}
this.server.password = password
} else {
if (this.server.debug) {
console.log("Password : Is empty".red)
}
this.server.success = false;
this.server.message = "You need to set a password"
}
// //If all is good
if (debug) {
console.log("Your Synology object is okay".green)
}
this.server.success = true;
this.Auth = new AuthClass(this.server);
this.DS = new DownloadStationClass(this.server, this.Auth);
}
// export the class
module.exports = SynologyAPI;
module.exports.Auth = this.Auth;
module.exports.DS = this.DS;