code refactor
This commit is contained in:
parent
f8e3a7e424
commit
edd3ac5c03
|
@ -1,12 +1,12 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').controller('CommandController', ['$rootScope', '$window', '$location', '$routeParams', 'base64', 'ariaNgDefaultOptions', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2SettingService', 'aria2TaskService', 'ariaNgLogService', function ($rootScope, $window, $location, $routeParams, base64, ariaNgDefaultOptions, ariaNgCommonService, ariaNgSettingService, aria2SettingService, aria2TaskService, ariaNgLogService) {
|
angular.module('ariaNg').controller('CommandController', ['$rootScope', '$window', '$location', '$routeParams', 'ariaNgDefaultOptions', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2SettingService', 'aria2TaskService', 'ariaNgLogService', function ($rootScope, $window, $location, $routeParams, ariaNgDefaultOptions, ariaNgCommonService, ariaNgSettingService, aria2SettingService, aria2TaskService, ariaNgLogService) {
|
||||||
var path = $location.path();
|
var path = $location.path();
|
||||||
|
|
||||||
var doNewTaskCommand = function (url, params) {
|
var doNewTaskCommand = function (url, params) {
|
||||||
try {
|
try {
|
||||||
url = base64.urldecode(url);
|
url = ariaNgCommonService.base64UrlDecode(url);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
ariaNgCommonService.showError('URL is not base64 encoded!');
|
ariaNgCommonService.showError('URL is not base64 encoded!');
|
||||||
return false;
|
return false;
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
|
|
||||||
if (secret) {
|
if (secret) {
|
||||||
try {
|
try {
|
||||||
secret = base64.urldecode(secret);
|
secret = ariaNgCommonService.base64UrlDecode(secret);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
ariaNgCommonService.showError('RPC secret is not base64 encoded!');
|
ariaNgCommonService.showError('RPC secret is not base64 encoded!');
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').controller('NewTaskController', ['$rootScope', '$scope', '$location', '$timeout', 'base64', 'ariaNgCommonService', 'ariaNgLogService', 'ariaNgSettingService', 'ariaNgFileService', 'aria2SettingService', 'aria2TaskService', function ($rootScope, $scope, $location, $timeout, base64, ariaNgCommonService, ariaNgLogService, ariaNgSettingService, ariaNgFileService, aria2SettingService, aria2TaskService) {
|
angular.module('ariaNg').controller('NewTaskController', ['$rootScope', '$scope', '$location', '$timeout', 'ariaNgCommonService', 'ariaNgLogService', 'ariaNgSettingService', 'ariaNgFileService', 'aria2SettingService', 'aria2TaskService', function ($rootScope, $scope, $location, $timeout, ariaNgCommonService, ariaNgLogService, ariaNgSettingService, ariaNgFileService, aria2SettingService, aria2TaskService) {
|
||||||
var tabOrders = ['links', 'options'];
|
var tabOrders = ['links', 'options'];
|
||||||
var parameters = $location.search();
|
var parameters = $location.search();
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@
|
||||||
|
|
||||||
if (parameters.url) {
|
if (parameters.url) {
|
||||||
try {
|
try {
|
||||||
$scope.context.urls = base64.urldecode(parameters.url);
|
$scope.context.urls = ariaNgCommonService.base64UrlDecode(parameters.url);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
ariaNgLogService.error('[NewTaskController] base64 decode error, url=' + parameters.url, ex);
|
ariaNgLogService.error('[NewTaskController] base64 decode error, url=' + parameters.url, ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'base64', 'ariaNgSettingService', 'ariaNgLogService', function ($http, base64, ariaNgSettingService, ariaNgLogService) {
|
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgLogService', function ($http, ariaNgCommonService, ariaNgSettingService, ariaNgLogService) {
|
||||||
var rpcUrl = ariaNgSettingService.getCurrentRpcUrl();
|
var rpcUrl = ariaNgSettingService.getCurrentRpcUrl();
|
||||||
var method = ariaNgSettingService.getCurrentRpcHttpMethod();
|
var method = ariaNgSettingService.getCurrentRpcHttpMethod();
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
if (angular.isObject(value) || angular.isArray(value)) {
|
if (angular.isObject(value) || angular.isArray(value)) {
|
||||||
value = angular.toJson(value);
|
value = angular.toJson(value);
|
||||||
value = base64.encode(value);
|
value = ariaNgCommonService.base64Encode(value);
|
||||||
value = encodeURIComponent(value);
|
value = encodeURIComponent(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,18 @@
|
||||||
|
|
||||||
angular.module('ariaNg').factory('ariaNgCommonService', ['$location', '$timeout', 'base64', 'moment', 'SweetAlert', '$translate', 'ariaNgConstants', function ($location, $timeout, base64, moment, SweetAlert, $translate, ariaNgConstants) {
|
angular.module('ariaNg').factory('ariaNgCommonService', ['$location', '$timeout', 'base64', 'moment', 'SweetAlert', '$translate', 'ariaNgConstants', function ($location, $timeout, base64, moment, SweetAlert, $translate, ariaNgConstants) {
|
||||||
return {
|
return {
|
||||||
|
base64Encode: function (value) {
|
||||||
|
return base64.encode(value);
|
||||||
|
},
|
||||||
|
base64Decode: function (value) {
|
||||||
|
return base64.decode(value);
|
||||||
|
},
|
||||||
|
base64UrlDecode: function (value) {
|
||||||
|
return base64.urldecode(value);
|
||||||
|
},
|
||||||
generateUniqueId: function () {
|
generateUniqueId: function () {
|
||||||
var sourceId = ariaNgConstants.appPrefix + '_' + Math.round(new Date().getTime() / 1000) + '_' + Math.random();
|
var sourceId = ariaNgConstants.appPrefix + '_' + Math.round(new Date().getTime() / 1000) + '_' + Math.random();
|
||||||
var hashedId = base64.encode(sourceId);
|
var hashedId = this.base64Encode(sourceId);
|
||||||
|
|
||||||
return hashedId;
|
return hashedId;
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', '$translate', 'base64', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgLogService', function ($window, $location, $filter, $translate, base64, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService, ariaNgLogService) {
|
angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', '$translate', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgLogService', function ($window, $location, $filter, $translate, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService, ariaNgLogService) {
|
||||||
var browserFeatures = (function () {
|
var browserFeatures = (function () {
|
||||||
var supportLocalStroage = localStorageService.isSupported;
|
var supportLocalStroage = localStorageService.isSupported;
|
||||||
var supportCookies = $window.navigator.cookieEnabled;
|
var supportCookies = $window.navigator.cookieEnabled;
|
||||||
|
@ -207,7 +207,7 @@
|
||||||
var options = angular.extend({}, ariaNgDefaultOptions, getOptions());
|
var options = angular.extend({}, ariaNgDefaultOptions, getOptions());
|
||||||
|
|
||||||
if (options.secret) {
|
if (options.secret) {
|
||||||
options.secret = base64.decode(options.secret);
|
options.secret = ariaNgCommonService.base64Decode(options.secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (angular.isArray(options.extendRpcServers)) {
|
if (angular.isArray(options.extendRpcServers)) {
|
||||||
|
@ -215,7 +215,7 @@
|
||||||
var rpcSetting = options.extendRpcServers[i];
|
var rpcSetting = options.extendRpcServers[i];
|
||||||
|
|
||||||
if (rpcSetting.secret) {
|
if (rpcSetting.secret) {
|
||||||
rpcSetting.secret = base64.decode(rpcSetting.secret);
|
rpcSetting.secret = ariaNgCommonService.base64Decode(rpcSetting.secret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@
|
||||||
},
|
},
|
||||||
getCurrentRpcSecret: function () {
|
getCurrentRpcSecret: function () {
|
||||||
var value = getOption('secret');
|
var value = getOption('secret');
|
||||||
return (value ? base64.decode(value) : value);
|
return (value ? ariaNgCommonService.base64Decode(value) : value);
|
||||||
},
|
},
|
||||||
addNewRpcSetting: function () {
|
addNewRpcSetting: function () {
|
||||||
var options = getOptions();
|
var options = getOptions();
|
||||||
|
@ -366,7 +366,7 @@
|
||||||
value = Math.max(parseInt(value), 0);
|
value = Math.max(parseInt(value), 0);
|
||||||
} else if (field === 'secret') {
|
} else if (field === 'secret') {
|
||||||
if (value) {
|
if (value) {
|
||||||
value = base64.encode(value);
|
value = ariaNgCommonService.base64Encode(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@
|
||||||
newDefaultSetting = cloneRpcSetting(setting);
|
newDefaultSetting = cloneRpcSetting(setting);
|
||||||
|
|
||||||
if (newDefaultSetting.secret) {
|
if (newDefaultSetting.secret) {
|
||||||
newDefaultSetting.secret = base64.encode(newDefaultSetting.secret);
|
newDefaultSetting.secret = ariaNgCommonService.base64Encode(newDefaultSetting.secret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue