This repository has been archived on 2022-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
AriaNg/app/scripts/services/aria2SettingService.js

111 lines
4.3 KiB
JavaScript
Raw Normal View History

2016-05-31 16:51:12 +02:00
(function () {
'use strict';
2016-06-01 18:02:10 +02:00
angular.module('ariaNg').factory('aria2SettingService', ['aria2AllOptions', 'aria2GlobalAvailableOptions', 'aria2TaskAvailableOptions', 'aria2RpcService', function (aria2AllOptions, aria2GlobalAvailableOptions, aria2TaskAvailableOptions, aria2RpcService) {
2016-05-31 16:51:12 +02:00
var processStatResult = function (stat) {
if (!stat) {
return stat;
}
2016-06-01 18:02:10 +02:00
2016-05-31 16:51:12 +02:00
var activeCount = parseInt(stat.numActive);
var waitingCount = parseInt(stat.numWaiting);
var totalRunningCount = activeCount + waitingCount;
stat.totalRunningCount = totalRunningCount;
2016-06-01 18:02:10 +02:00
2016-05-31 16:51:12 +02:00
return stat;
};
2016-06-01 18:02:10 +02:00
2016-05-31 16:51:12 +02:00
return {
2016-06-01 18:02:10 +02:00
getAvailableGlobalOptionsKeys: function (type) {
2016-05-31 16:51:12 +02:00
if (type == 'basic') {
return aria2GlobalAvailableOptions.basicOptions;
} else if (type == 'http-ftp-sftp') {
return aria2GlobalAvailableOptions.httpFtpSFtpOptions;
} else if (type == 'http') {
return aria2GlobalAvailableOptions.httpOptions;
} else if (type == 'ftp-sftp') {
return aria2GlobalAvailableOptions.ftpSFtpOptions;
} else if (type == 'bt') {
return aria2GlobalAvailableOptions.btOptions;
} else if (type == 'metalink') {
return aria2GlobalAvailableOptions.metalinkOptions;
} else if (type == 'rpc') {
return aria2GlobalAvailableOptions.rpcOptions;
} else if (type == 'advanced') {
return aria2GlobalAvailableOptions.advancedOptions;
} else {
return false;
}
},
2016-06-01 18:02:10 +02:00
getAvailableTaskOptionKeys: function (status, isBittorrent) {
if (status == 'active' && isBittorrent) {
return aria2TaskAvailableOptions.activeBtOptions;
} else if (status == 'active' && !isBittorrent) {
return aria2TaskAvailableOptions.activeOtherOptions;
} else if ((status == 'waiting' || status == 'paused') && isBittorrent) {
return aria2TaskAvailableOptions.activeBtOptions;
} else if ((status == 'waiting' || status == 'paused') && !isBittorrent) {
return aria2TaskAvailableOptions.activeOtherOptions;
} else {
return false;
}
},
2016-05-31 16:51:12 +02:00
getSpecifiedOptions: function (keys) {
var options = [];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var option = aria2AllOptions[key];
if (!option) {
continue;
}
option = angular.extend({
key: key,
nameKey: 'options.' + key + '.name',
descriptionKey: 'options.' + key + '.description'
}, option);
options.push(option);
}
return options;
},
getGlobalOption: function (callback) {
return aria2RpcService.getGlobalOption({
callback: callback
});
},
setGlobalOption: function (key, value, callback) {
var data = {};
data[key] = value;
return aria2RpcService.changeGlobalOption({
options: data,
callback: callback
});
},
getServerStatus: function (callback) {
return aria2RpcService.getVersion({
callback: callback
})
},
2016-06-04 09:33:40 +02:00
getGlobalStat: function (callback, silent) {
2016-05-31 16:51:12 +02:00
return aria2RpcService.getGlobalStat({
2016-06-04 09:33:40 +02:00
silent: !!silent,
2016-05-31 16:51:12 +02:00
callback: function (result) {
if (!callback) {
return;
}
var stat = processStatResult(result);
callback(stat);
}
});
}
};
}]);
})();