refactor code
This commit is contained in:
parent
7cd76f5571
commit
7d6b5e2668
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('ariaNg').constant('aria2AllOptions', {
|
angular.module('ariaNg').constant('aria2AllOptions', {
|
||||||
// EXAMPLE:
|
// EXAMPLE:
|
||||||
// 'option name': {
|
// 'option key': {
|
||||||
// type: 'string|integer|float|text|boolean|option',
|
// type: 'string|integer|float|text|boolean|option',
|
||||||
// [suffix: 'Bytes|Milliseconds|Seconds|Minutes|Hours',]
|
// [suffix: 'Bytes|Milliseconds|Seconds|Minutes|Hours',]
|
||||||
// [defaultValue: '',]
|
// [defaultValue: '',]
|
||||||
|
@ -798,11 +798,109 @@
|
||||||
rpcOptions: ['enable-rpc', 'pause-metadata', 'rpc-allow-origin-all', 'rpc-listen-all', 'rpc-listen-port', 'rpc-max-request-size', 'rpc-save-upload-metadata', 'rpc-secure'],
|
rpcOptions: ['enable-rpc', 'pause-metadata', 'rpc-allow-origin-all', 'rpc-listen-all', 'rpc-listen-port', 'rpc-max-request-size', 'rpc-save-upload-metadata', 'rpc-secure'],
|
||||||
advancedOptions: ['allow-overwrite', 'allow-piece-length-change', 'always-resume', 'async-dns', 'auto-file-renaming', 'auto-save-interval', 'conditional-get', 'conf-path', 'console-log-level', 'daemon', 'deferred-input', 'disable-ipv6', 'disk-cache', 'download-result', 'dscp', 'rlimit-nofile', 'enable-color', 'enable-mmap', 'event-poll', 'file-allocation', 'force-save', 'hash-check-only', 'human-readable', 'max-download-result', 'max-mmap-limit', 'max-resume-failure-tries', 'min-tls-version', 'log-level', 'optimize-concurrent-downloads', 'piece-length', 'show-console-readout', 'summary-interval', 'max-overall-download-limit', 'max-download-limit', 'no-conf', 'no-file-allocation-limit', 'parameterized-uri', 'quiet', 'realtime-chunk-checksum', 'remove-control-file', 'save-session', 'save-session-interval', 'socket-recv-buffer-size', 'stop', 'truncate-console-readout']
|
advancedOptions: ['allow-overwrite', 'allow-piece-length-change', 'always-resume', 'async-dns', 'auto-file-renaming', 'auto-save-interval', 'conditional-get', 'conf-path', 'console-log-level', 'daemon', 'deferred-input', 'disable-ipv6', 'disk-cache', 'download-result', 'dscp', 'rlimit-nofile', 'enable-color', 'enable-mmap', 'event-poll', 'file-allocation', 'force-save', 'hash-check-only', 'human-readable', 'max-download-result', 'max-mmap-limit', 'max-resume-failure-tries', 'min-tls-version', 'log-level', 'optimize-concurrent-downloads', 'piece-length', 'show-console-readout', 'summary-interval', 'max-overall-download-limit', 'max-download-limit', 'no-conf', 'no-file-allocation-limit', 'parameterized-uri', 'quiet', 'realtime-chunk-checksum', 'remove-control-file', 'save-session', 'save-session-interval', 'socket-recv-buffer-size', 'stop', 'truncate-console-readout']
|
||||||
}).constant('aria2TaskAvailableOptions', {
|
}).constant('aria2TaskAvailableOptions', {
|
||||||
activeNormalTaskOptions: ['max-download-limit', 'max-upload-limit', 'force-save'],
|
taskOptions: [
|
||||||
activeBtTaskOptions: ['max-download-limit', 'max-upload-limit', 'bt-max-peers', 'bt-request-peer-speed-limit', 'bt-remove-unselected-file', 'force-save'],
|
{
|
||||||
inactiveNormalTaskOptions: ['max-download-limit', 'max-upload-limit', 'split', 'min-split-size', 'max-connection-per-server', 'force-save'],
|
key: 'dir',
|
||||||
inactiveBtTaskOptions: ['max-download-limit', 'max-upload-limit', 'split', 'min-split-size', 'max-connection-per-server', 'bt-max-peers', 'bt-request-peer-speed-limit', 'bt-remove-unselected-file', 'force-save'],
|
newOnly: true
|
||||||
activeTaskReadonlyOptions: ['split', 'min-split-size', 'max-connection-per-server'],
|
},
|
||||||
newTaskOptions: ['dir', 'max-download-limit', 'max-upload-limit', 'split', 'min-split-size', 'max-connection-per-server', 'allow-overwrite', 'conditional-get', 'file-allocation', 'stream-piece-selector', 'parameterized-uri']
|
{
|
||||||
|
key: 'allow-overwrite',
|
||||||
|
newOnly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'max-download-limit'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'max-upload-limit',
|
||||||
|
btOnly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'split',
|
||||||
|
httpOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'min-split-size',
|
||||||
|
httpOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'max-connection-per-server',
|
||||||
|
httpOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'lowest-speed-limit',
|
||||||
|
httpOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'stream-piece-selector',
|
||||||
|
httpOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'all-proxy',
|
||||||
|
httpOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'all-proxy-user',
|
||||||
|
httpOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'all-proxy-passwd',
|
||||||
|
httpOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'bt-max-peers',
|
||||||
|
btOnly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'bt-request-peer-speed-limit',
|
||||||
|
btOnly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'bt-remove-unselected-file',
|
||||||
|
btOnly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'bt-stop-timeout',
|
||||||
|
btOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'bt-tracker',
|
||||||
|
btOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'seed-ratio',
|
||||||
|
btOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'seed-time',
|
||||||
|
btOnly: true,
|
||||||
|
activeReadonly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'conditional-get',
|
||||||
|
newOnly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'file-allocation',
|
||||||
|
newOnly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'parameterized-uri ',
|
||||||
|
newOnly: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'force-save'
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -13,11 +13,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = [];
|
return aria2SettingService.getSpecifiedOptions(keys);
|
||||||
ariaNgCommonService.pushArrayTo(options, aria2SettingService.getSpecifiedOptions(keys.readwrite));
|
|
||||||
ariaNgCommonService.pushArrayTo(options, aria2SettingService.getSpecifiedOptions(keys.readonly, true));
|
|
||||||
|
|
||||||
return options;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var refreshBtPeers = function (task, silent) {
|
var refreshBtPeers = function (task, silent) {
|
||||||
|
|
|
@ -39,38 +39,63 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getAvailableTaskOptionKeys: function (status, isBittorrent) {
|
getAvailableTaskOptionKeys: function (status, isBittorrent) {
|
||||||
if (status == 'active' && isBittorrent) {
|
var allOptions = aria2TaskAvailableOptions.taskOptions;
|
||||||
return {
|
var availableOptions = [];
|
||||||
readwrite: aria2TaskAvailableOptions.activeBtTaskOptions,
|
|
||||||
readonly: aria2TaskAvailableOptions.activeTaskReadonlyOptions
|
for (var i = 0; i < allOptions.length; i++) {
|
||||||
|
var option = allOptions[i];
|
||||||
|
var optionKey = {
|
||||||
|
key: option.key
|
||||||
};
|
};
|
||||||
} else if (status == 'active' && !isBittorrent) {
|
|
||||||
return {
|
if (option.newOnly) {
|
||||||
readwrite: aria2TaskAvailableOptions.activeNormalTaskOptions,
|
continue;
|
||||||
readonly: aria2TaskAvailableOptions.activeTaskReadonlyOptions
|
|
||||||
};
|
|
||||||
} else if ((status == 'waiting' || status == 'paused') && isBittorrent) {
|
|
||||||
return {
|
|
||||||
readwrite: aria2TaskAvailableOptions.inactiveBtTaskOptions,
|
|
||||||
readonly: []
|
|
||||||
};
|
|
||||||
} else if ((status == 'waiting' || status == 'paused') && !isBittorrent) {
|
|
||||||
return {
|
|
||||||
readwrite: aria2TaskAvailableOptions.inactiveNormalTaskOptions,
|
|
||||||
readonly: []
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (option.httpOnly && isBittorrent) {
|
||||||
|
continue;
|
||||||
|
} else if (option.btOnly && !isBittorrent) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (option.activeReadonly && status == 'active') {
|
||||||
|
optionKey.readonly = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
availableOptions.push(optionKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return availableOptions;
|
||||||
},
|
},
|
||||||
getNewTaskOptionKeys: function (isBittorrent) {
|
getNewTaskOptionKeys: function (isBittorrent) {
|
||||||
return aria2TaskAvailableOptions.newTaskOptions;
|
var allOptions = aria2TaskAvailableOptions.taskOptions;
|
||||||
|
var availableOptions = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < allOptions.length; i++) {
|
||||||
|
var option = allOptions[i];
|
||||||
|
var optionKey = {
|
||||||
|
key: option.key
|
||||||
|
};
|
||||||
|
|
||||||
|
availableOptions.push(optionKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return availableOptions;
|
||||||
},
|
},
|
||||||
getSpecifiedOptions: function (keys, readonly) {
|
getSpecifiedOptions: function (keys) {
|
||||||
var options = [];
|
var options = [];
|
||||||
|
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
var key = keys[i];
|
var key = keys[i];
|
||||||
|
var readonly = false;
|
||||||
|
|
||||||
|
if (angular.isObject(key)) {
|
||||||
|
var optionKey = key;
|
||||||
|
|
||||||
|
key = optionKey.key;
|
||||||
|
readonly = !!optionKey.readonly;
|
||||||
|
}
|
||||||
|
|
||||||
var option = aria2AllOptions[key];
|
var option = aria2AllOptions[key];
|
||||||
|
|
||||||
if (!option) {
|
if (!option) {
|
||||||
|
@ -87,7 +112,7 @@
|
||||||
option.options = ['true', 'false'];
|
option.options = ['true', 'false'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!!readonly) {
|
if (readonly) {
|
||||||
option.readonly = true;
|
option.readonly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue