Improve handling of multiple torrent file URLs

This commit is contained in:
John Furrow
2015-11-08 16:02:51 -08:00
parent 1304541544
commit 7a4f9a7e51
+29 -20
View File
@@ -10,28 +10,37 @@ function client() {
};
client.prototype.add = function(data, callback) {
var commands = [
[
{
methodName: 'execute',
params: [
'mkdir',
'-p',
data.destination
]
},
{
methodName: 'load.start',
params: [
'',
data.url,
'd.directory.set="' + data.destination + '"'
]
}
]
var multicall = [
[]
];
rTorrent.get('system.multicall', commands).then(function(data) {
if (data.destination !== null && data.destination !== '') {
multicall[0].push({
methodName: 'execute',
params: [
'mkdir',
'-p',
data.destination
]
});
}
var torrentsAdded = 0;
while (torrentsAdded < data.urls.length) {
multicall[0].push({
methodName: 'load.start',
params: [
'',
data.urls[torrentsAdded],
'd.directory.set="' + data.destination + '"'
]
});
torrentsAdded++;
}
rTorrent.get('system.multicall', multicall).then(function(data) {
callback(null, data);
}, function(error) {
callback(error, null);