code refactor

This commit is contained in:
MaysWind 2018-08-12 16:59:21 +08:00
parent f8e3a7e424
commit edd3ac5c03
5 changed files with 23 additions and 14 deletions

View file

@ -1,12 +1,12 @@
(function () {
'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 doNewTaskCommand = function (url, params) {
try {
url = base64.urldecode(url);
url = ariaNgCommonService.base64UrlDecode(url);
} catch (ex) {
ariaNgCommonService.showError('URL is not base64 encoded!');
return false;
@ -70,7 +70,7 @@
if (secret) {
try {
secret = base64.urldecode(secret);
secret = ariaNgCommonService.base64UrlDecode(secret);
} catch (ex) {
ariaNgCommonService.showError('RPC secret is not base64 encoded!');
return false;

View file

@ -1,7 +1,7 @@
(function () {
'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 parameters = $location.search();
@ -79,7 +79,7 @@
if (parameters.url) {
try {
$scope.context.urls = base64.urldecode(parameters.url);
$scope.context.urls = ariaNgCommonService.base64UrlDecode(parameters.url);
} catch (ex) {
ariaNgLogService.error('[NewTaskController] base64 decode error, url=' + parameters.url, ex);
}

View file

@ -1,7 +1,7 @@
(function () {
'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 method = ariaNgSettingService.getCurrentRpcHttpMethod();
@ -29,7 +29,7 @@
if (angular.isObject(value) || angular.isArray(value)) {
value = angular.toJson(value);
value = base64.encode(value);
value = ariaNgCommonService.base64Encode(value);
value = encodeURIComponent(value);
}

View file

@ -3,9 +3,18 @@
angular.module('ariaNg').factory('ariaNgCommonService', ['$location', '$timeout', 'base64', 'moment', 'SweetAlert', '$translate', 'ariaNgConstants', function ($location, $timeout, base64, moment, SweetAlert, $translate, ariaNgConstants) {
return {
base64Encode: function (value) {
return base64.encode(value);
},
base64Decode: function (value) {
return base64.decode(value);
},
base64UrlDecode: function (value) {
return base64.urldecode(value);
},
generateUniqueId: function () {
var sourceId = ariaNgConstants.appPrefix + '_' + Math.round(new Date().getTime() / 1000) + '_' + Math.random();
var hashedId = base64.encode(sourceId);
var hashedId = this.base64Encode(sourceId);
return hashedId;
},

View file

@ -1,7 +1,7 @@
(function () {
'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 supportLocalStroage = localStorageService.isSupported;
var supportCookies = $window.navigator.cookieEnabled;
@ -207,7 +207,7 @@
var options = angular.extend({}, ariaNgDefaultOptions, getOptions());
if (options.secret) {
options.secret = base64.decode(options.secret);
options.secret = ariaNgCommonService.base64Decode(options.secret);
}
if (angular.isArray(options.extendRpcServers)) {
@ -215,7 +215,7 @@
var rpcSetting = options.extendRpcServers[i];
if (rpcSetting.secret) {
rpcSetting.secret = base64.decode(rpcSetting.secret);
rpcSetting.secret = ariaNgCommonService.base64Decode(rpcSetting.secret);
}
}
}
@ -333,7 +333,7 @@
},
getCurrentRpcSecret: function () {
var value = getOption('secret');
return (value ? base64.decode(value) : value);
return (value ? ariaNgCommonService.base64Decode(value) : value);
},
addNewRpcSetting: function () {
var options = getOptions();
@ -366,7 +366,7 @@
value = Math.max(parseInt(value), 0);
} else if (field === 'secret') {
if (value) {
value = base64.encode(value);
value = ariaNgCommonService.base64Encode(value);
}
}
@ -439,7 +439,7 @@
newDefaultSetting = cloneRpcSetting(setting);
if (newDefaultSetting.secret) {
newDefaultSetting.secret = base64.encode(newDefaultSetting.secret);
newDefaultSetting.secret = ariaNgCommonService.base64Encode(newDefaultSetting.secret);
}
}