command line api support set rpc
This commit is contained in:
parent
d61ba34b2a
commit
36ec36b58f
|
@ -177,12 +177,15 @@ Disabled=禁用
|
|||
BitTorrent=BitTorrent
|
||||
Changes to the settings take effect after refreshing page.=设置将在页面刷新后生效.
|
||||
Type is illegal!=类型错误!
|
||||
Parameter is invalid!=请求参数无效
|
||||
Parameter is invalid!=请求参数无效!
|
||||
Option value cannot be empty!=参数内容不能为空!
|
||||
Input number is invalid!=输入的数字无效!
|
||||
Input number is below min value!=输入的数字小于最小值 {{value}} !
|
||||
Input number is above max value!=输入的数字大于最大值 {{value}} !
|
||||
Input value is invalid!=输入的内容无效!
|
||||
Protocol is invalid!=协议无效!
|
||||
RPC host cannot be empty!=RPC 主机不能为空!
|
||||
RPC secret is not base64 encoded!=RPC 密钥不是 Base64 编码后的字符串!
|
||||
Tap to configure and get started with AriaNg.=您还没有进行过设置, 点击这里进行设置.
|
||||
|
||||
[error]
|
||||
|
|
|
@ -187,6 +187,9 @@
|
|||
'Input number is below min value!': 'Input number is below min value {{value}}!',
|
||||
'Input number is above max value!': 'Input number is above max value {{value}}!',
|
||||
'Input value is invalid!': 'Input value is invalid!',
|
||||
'Protocol is invalid!': 'Protocol is invalid!',
|
||||
'RPC host cannot be empty!': 'RPC host cannot be empty!',
|
||||
'RPC secret is not base64 encoded!': 'RPC secret is not base64 encoded!',
|
||||
'Tap to configure and get started with AriaNg.': 'Tap to configure and get started with AriaNg.',
|
||||
'error': {
|
||||
'unknown': 'Unknown error occurred.',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').controller('CommandController', ['$rootScope', '$location', '$routeParams', 'base64', 'ariaNgCommonService', 'aria2TaskService', 'ariaNgLogService', function ($rootScope, $location, $routeParams, base64, ariaNgCommonService, aria2TaskService, ariaNgLogService) {
|
||||
angular.module('ariaNg').controller('CommandController', ['$rootScope', '$window', '$location', '$routeParams', 'base64', 'ariaNgDefaultOptions', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2TaskService', 'ariaNgLogService', function ($rootScope, $window, $location, $routeParams, base64, ariaNgDefaultOptions, ariaNgCommonService, ariaNgSettingService, aria2TaskService, ariaNgLogService) {
|
||||
var path = $location.path();
|
||||
|
||||
var newUrlDownload = function (url) {
|
||||
|
@ -22,8 +22,57 @@
|
|||
var url = base64.urldecode(base64Url);
|
||||
$rootScope.loadPromise = newUrlDownload(url);
|
||||
ariaNgLogService.info('[CommandController] new download: ' + url);
|
||||
} else if (path.indexOf('/settings/rpc/set/') === 0) {
|
||||
var rpcProtocol = $routeParams.protocol;
|
||||
var rpcHost = $routeParams.host;
|
||||
var rpcPort = $routeParams.port || ariaNgDefaultOptions.rpcPort;
|
||||
var rpcInterface =$routeParams.interface || ariaNgDefaultOptions.rpcInterface;
|
||||
var secret = $routeParams.secret || ariaNgDefaultOptions.secret;
|
||||
|
||||
ariaNgLogService.info('[CommandController] set rpc: ' + rpcProtocol + '://' + rpcHost + ':' + rpcPort + '/' + rpcInterface + ', secret: ' + secret);
|
||||
|
||||
if (!rpcProtocol || (rpcProtocol !== 'http' && rpcProtocol !== 'https' && rpcProtocol !== 'ws' && rpcProtocol !== 'wss')) {
|
||||
ariaNgCommonService.showError('Protocol is invalid!');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rpcHost) {
|
||||
ariaNgCommonService.showError('RPC host cannot be empty!');
|
||||
return;
|
||||
}
|
||||
|
||||
if (secret) {
|
||||
try {
|
||||
secret = base64.urldecode(secret);
|
||||
} catch (ex) {
|
||||
ariaNgCommonService.showError('RPC secret is not base64 encoded!');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var newSetting = {
|
||||
rpcAlias: '',
|
||||
rpcHost: rpcHost,
|
||||
rpcPort: rpcPort,
|
||||
rpcInterface: rpcInterface,
|
||||
protocol: rpcProtocol,
|
||||
httpMethod: ariaNgDefaultOptions.httpMethod,
|
||||
secret: secret
|
||||
};
|
||||
|
||||
if (ariaNgSettingService.isRpcSettingEqualsDefault(newSetting)) {
|
||||
$location.path('/downloading');
|
||||
} else {
|
||||
ariaNgCommonService.error('Parameter is invalid!');
|
||||
ariaNgSettingService.setDefaultRpcSetting(newSetting, {
|
||||
keepCurrent: false,
|
||||
forceSet: true
|
||||
});
|
||||
|
||||
$location.path('/downloading');
|
||||
$window.location.reload();
|
||||
}
|
||||
} else {
|
||||
ariaNgCommonService.showError('Parameter is invalid!');
|
||||
}
|
||||
}]);
|
||||
}());
|
||||
|
|
|
@ -67,6 +67,10 @@
|
|||
templateUrl: 'views/settings-aria2.html',
|
||||
controller: 'Aria2SettingsController'
|
||||
})
|
||||
.when('/settings/rpc/set/:protocol/:host/:port/:interface/:secret?', {
|
||||
template: '',
|
||||
controller: 'CommandController'
|
||||
})
|
||||
.when('/status', {
|
||||
templateUrl: 'views/status.html',
|
||||
controller: 'Aria2StatusController'
|
||||
|
|
|
@ -297,7 +297,12 @@
|
|||
|
||||
return setting;
|
||||
},
|
||||
setDefaultRpcSetting: function (setting) {
|
||||
setDefaultRpcSetting: function (setting, params) {
|
||||
params = angular.extend({
|
||||
keepCurrent: true,
|
||||
forceSet: false
|
||||
}, params);
|
||||
|
||||
var options = getOptions();
|
||||
var currentSetting = cloneRpcSetting(options);
|
||||
currentSetting.rpcId = ariaNgCommonService.generateUniqueId();
|
||||
|
@ -316,8 +321,19 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (params.forceSet) {
|
||||
newDefaultSetting = cloneRpcSetting(setting);
|
||||
|
||||
if (newDefaultSetting.secret) {
|
||||
newDefaultSetting.secret = base64.encode(newDefaultSetting.secret);
|
||||
}
|
||||
}
|
||||
|
||||
if (newDefaultSetting) {
|
||||
if (params.keepCurrent) {
|
||||
options.extendRpcServers.splice(0, 0, currentSetting);
|
||||
}
|
||||
|
||||
options = angular.extend(options, newDefaultSetting);
|
||||
}
|
||||
|
||||
|
@ -325,6 +341,39 @@
|
|||
|
||||
return setting;
|
||||
},
|
||||
isRpcSettingEqualsDefault: function (setting) {
|
||||
if (!setting) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var options = this.getAllOptions();
|
||||
|
||||
if (options.rpcHost !== setting.rpcHost) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.rpcPort !== setting.rpcPort) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.rpcInterface !== setting.rpcInterface) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.protocol !== setting.protocol) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.httpMethod !== setting.httpMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.secret !== setting.secret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
getGlobalStatRefreshInterval: function () {
|
||||
return getOption('globalStatRefreshInterval');
|
||||
},
|
||||
|
|
Reference in a new issue