-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncthingclient.js
46 lines (40 loc) · 1.1 KB
/
syncthingclient.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
const syncthing = require('node-syncthing')
const Promise = require('promise')
function SyncthingClient(json) {
if(!json.syncthingHost) {
return null
}
const options = {
host: json.syncthingHost,
port: json.syncthingPort,
apiKey: json.syncthingApiKey,
username: json.syncthingUsername,
password: json.syncthingPassword,
https: json.syncthingSecure
};
this.folder = json.syncthingFolderID
this.client = syncthing(options)
}
SyncthingClient.prototype.status = function () {
let self = this;
return new Promise(function (fulfill, reject) {
self.client.db.status(self.folder).then( result => {
fulfill(result)
}, error => {
reject(error)
});
});
}
SyncthingClient.prototype.browse = function () {
let self = this;
return new Promise(function (fulfill, reject) {
self.client.db.browse(self.folder).then( result => {
fulfill(result)
}, error => {
reject(error)
});
});
}
module.exports = {
SyncthingClient: SyncthingClient
}