2016-06-25 13:47:02 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2017-03-20 16:35:34 +01:00
|
|
|
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) {
|
2016-06-25 13:47:02 +02:00
|
|
|
var path = $location.path();
|
|
|
|
|
|
|
|
var newUrlDownload = function (url) {
|
|
|
|
return aria2TaskService.newUriTask({
|
|
|
|
urls: [url],
|
|
|
|
options: {}
|
|
|
|
}, false, function (response) {
|
|
|
|
if (!response.success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$location.path('/downloading');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-01 16:49:16 +02:00
|
|
|
if (path.indexOf('/new/') === 0) {
|
2016-06-25 13:47:02 +02:00
|
|
|
var base64Url = $routeParams.url;
|
|
|
|
var url = base64.urldecode(base64Url);
|
|
|
|
$rootScope.loadPromise = newUrlDownload(url);
|
2016-12-10 18:50:25 +01:00
|
|
|
ariaNgLogService.info('[CommandController] new download: ' + url);
|
2017-03-20 16:35:34 +01:00
|
|
|
} 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 {
|
|
|
|
ariaNgSettingService.setDefaultRpcSetting(newSetting, {
|
|
|
|
keepCurrent: false,
|
|
|
|
forceSet: true
|
|
|
|
});
|
|
|
|
|
|
|
|
$location.path('/downloading');
|
|
|
|
$window.location.reload();
|
|
|
|
}
|
2016-06-25 13:47:02 +02:00
|
|
|
} else {
|
2017-03-20 16:35:34 +01:00
|
|
|
ariaNgCommonService.showError('Parameter is invalid!');
|
2016-06-25 13:47:02 +02:00
|
|
|
}
|
|
|
|
}]);
|
2016-08-01 16:49:16 +02:00
|
|
|
}());
|