webui-aria2/js/services/rpc/helpers.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

angular.module('webui.services.rpc.helpers', [
'webui.services.deps', 'webui.services.rpc', 'webui.services.alerts'
])
.factory('$rpchelpers', ['$_', '$rpc', '$alerts', function(_, rpc, alerts) {
var miscellaneous = {version: '', enabledFeatures: []};
rpc.once('getVersion', [], function(data) { miscellaneous = data[0]});
return {
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) {
_.each(uris, function(uri) {
uri_parsed = [];
// parse options passed in the URIs. E.g. http://ex1.com/f1.jpg --out=image.jpg --check-integrity
_.each(uri, function(uri_element) {
if (uri_element.startsWith('--')) {
uri_options = uri_element.split(/--|=(.*)/);
if (uri_options.length > 2) {
settings[uri_options[2]] = uri_options[3] || 'true';
}
}
else {
uri_parsed.push(uri_element);
}
});
// passing true to batch all the addUri calls
rpc.once('addUri', [uri_parsed, settings], cb, true);
});
// now dispatch all addUri syscalls
rpc.forceUpdate();
},
2014-09-01 21:15:33 +02:00
addTorrents: function(txts, settings, cb) {
_.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);
});
// now dispatch all addUri syscalls
rpc.forceUpdate();
},
2014-09-01 21:15:33 +02:00
addMetalinks: function(txts, settings, cb) {
_.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);
});
// now dispatch all addUri syscalls
rpc.forceUpdate();
}
};
}]);