Properly start/stop torrents

This commit is contained in:
John Furrow
2016-02-14 17:49:02 -08:00
parent 0bf9594c97
commit 96e008d725

View File

@@ -269,42 +269,64 @@ var client = {
}); });
}, },
stopTorrent: function(hash, callback) { stopTorrent: function(hashes, callback) {
if (!util.isArray(hash)) { if (!util.isArray(hashes)) {
hash = [hash]; hashes = [hashes];
} else { } else {
hash = String(hash).split(','); hashes = String(hashes).split(',');
} }
for (i = 0, len = hash.length; i < len; i++) { var multicall = [
rTorrent.get('d.close', [hash[i]]).then(function(data) { []
callback(null, data); ];
}, function(error) {
callback(error, null); hashes.forEach(function (hash) {
multicall[0].push({
methodName: 'd.stop',
params: [hash]
}); });
} multicall[0].push({
methodName: 'd.close',
params: [hash]
});
});
rTorrent.get('system.multicall', multicall)
.then(function(data) {
callback(null, data);
}, function(error) {
callback(error, null);
});
}, },
startTorrent: function(hash, callback) { startTorrent: function(hashes, callback) {
if (!util.isArray(hash)) { if (!util.isArray(hashes)) {
hash = [hash]; hashes = [hashes];
} else { } else {
hash = String(hash).split(','); hashes = String(hashes).split(',');
} }
for (i = 0, len = hash.length; i < len; i++) { var multicall = [
rTorrent.get('d.resume', [hash[i]]).then(function(data) { []
callback(null, data); ];
}, function(error) {
callback(error, null);
});
rTorrent.get('d.start', [hash[i]]).then(function(data) { hashes.forEach(function (hash) {
callback(null, data); multicall[0].push({
}, function(error) { methodName: 'd.open',
callback(error, null); params: [hash]
}); });
} multicall[0].push({
methodName: 'd.start',
params: [hash]
});
});
rTorrent.get('system.multicall', multicall)
.then(function(data) {
callback(null, data);
}, function(error) {
callback(error, null);
});
}, },
getTransferStats: function(callback) { getTransferStats: function(callback) {