-
Notifications
You must be signed in to change notification settings - Fork 0
/
tixati_remote.js
executable file
·76 lines (69 loc) · 2.22 KB
/
tixati_remote.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
/**
* Created by Saurabh on 27/06/2015.
*/
var request = require('request');
var cheerio = require('cheerio');
var querystring = require('querystring');
remote = new TixatiRemote(
'127.0.0.1',
'8888',
'user',
'user'
);
function TixatiRemote(host, port, username, password){
this.url = 'http://'+host+':'+port;
this.connection = require('http-digest-client')(host, port, username, password, false);
this.transfers = [];
var self = this;
this.printTransfers = function(){
console.log(self.transfers);
};
this.startTransfer = function(path){
var data = querystring.stringify({
start:'start'
});
self.connection.request({
path: path+'/action',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
},
data:data
},
function(res){
res.setEncoding('utf8');
res.on('data', function (chunk) {
//console.log('Response: ' + chunk);
});
res.on('end', function(){
console.log('end');
});
});
};
this.getTransfers = function(){
this.connection.request({
path: '/transfers',
method: 'GET'
},
function (res) {
res.setEncoding();
var buffer="";
res.on('data', function (data) {
buffer += data;
});
res.on('end', function(){
var $ = cheerio.load(buffer);
$('.xferstable tr td a').each(function() {
self.transfers.push($(this).attr('href'));
});
self.printTransfers();
self.startTransfer(self.transfers[1]);
});
res.on('error', function (err) {
console.log('Error loading');
});
}
);
};
}