2013-01-29 18:52:30 +01:00
|
|
|
angular.module('webui.services.rpc.helpers', [
|
2013-02-22 20:44:10 +01:00
|
|
|
'webui.services.deps', 'webui.services.rpc', 'webui.services.alerts'
|
2013-01-29 18:52:30 +01:00
|
|
|
])
|
2013-02-22 20:44:10 +01:00
|
|
|
.factory('$rpchelpers', ['$_', '$rpc', '$alerts', function(_, rpc, alerts) {
|
2013-03-20 08:45:28 +01:00
|
|
|
var miscellaneous = {version: '', enabledFeatures: []};
|
|
|
|
rpc.once('getVersion', [], function(data) { miscellaneous = data[0]});
|
2013-01-29 18:52:30 +01:00
|
|
|
return {
|
2013-03-20 08:45:28 +01:00
|
|
|
isFeatureEnabled: function(feature) {
|
|
|
|
return miscellaneous.enabledFeatures.indexOf(feature) != -1;
|
|
|
|
},
|
|
|
|
getAria2Version: function() {
|
|
|
|
return miscellaneous.version;
|
|
|
|
},
|
2014-09-01 21:15:33 +02:00
|
|
|
addUris: function(uris, settings, cb) {
|
2013-01-29 18:52:30 +01:00
|
|
|
_.each(uris, function(uri) {
|
2015-10-27 21:07:49 +01:00
|
|
|
var uri_parsed = [];
|
2014-12-15 11:30:39 +01:00
|
|
|
// parse options passed in the URIs. E.g. http://ex1.com/f1.jpg --out=image.jpg --check-integrity
|
2015-07-11 07:28:53 +02:00
|
|
|
var uriSettings = _.cloneDeep(settings);
|
2014-12-15 11:30:39 +01:00
|
|
|
_.each(uri, function(uri_element) {
|
|
|
|
if (uri_element.startsWith('--')) {
|
|
|
|
uri_options = uri_element.split(/--|=(.*)/);
|
|
|
|
if (uri_options.length > 2) {
|
2015-07-11 07:28:53 +02:00
|
|
|
uriSettings[uri_options[2]] = uri_options[3] || 'true';
|
2014-12-15 11:30:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uri_parsed.push(uri_element);
|
|
|
|
}
|
|
|
|
});
|
2013-01-29 18:52:30 +01:00
|
|
|
// passing true to batch all the addUri calls
|
2015-07-11 07:28:53 +02:00
|
|
|
rpc.once('addUri', [uri_parsed, uriSettings], cb, true);
|
2013-01-29 18:52:30 +01:00
|
|
|
});
|
|
|
|
|
2013-01-30 07:13:38 +01:00
|
|
|
// now dispatch all addUri syscalls
|
|
|
|
rpc.forceUpdate();
|
|
|
|
},
|
2014-09-01 21:15:33 +02:00
|
|
|
addTorrents: function(txts, settings, cb) {
|
2013-01-30 07:13:38 +01:00
|
|
|
_.each(txts, function(txt) {
|
|
|
|
// passing true to batch all the addUri calls
|
2014-09-01 21:15:33 +02:00
|
|
|
rpc.once('addTorrent', [txt, [], settings], cb, true);
|
2013-01-30 07:13:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// now dispatch all addUri syscalls
|
|
|
|
rpc.forceUpdate();
|
|
|
|
},
|
2014-09-01 21:15:33 +02:00
|
|
|
addMetalinks: function(txts, settings, cb) {
|
2013-01-30 07:13:38 +01:00
|
|
|
_.each(txts, function(txt) {
|
|
|
|
// passing true to batch all the addUri calls
|
2014-09-01 21:15:33 +02:00
|
|
|
rpc.once('addMetalink', [txt, settings], cb, true);
|
2013-01-30 07:13:38 +01:00
|
|
|
});
|
|
|
|
|
2013-01-29 18:52:30 +01:00
|
|
|
// now dispatch all addUri syscalls
|
|
|
|
rpc.forceUpdate();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|