Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Aug 12, 2018
1 parent f8e3a7e commit edd3ac5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/scripts/controllers/command.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/controllers/new.js
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/services/aria2HttpRpcService.js
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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);
}

Expand Down
11 changes: 10 additions & 1 deletion src/scripts/services/ariaNgCommonService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
12 changes: 6 additions & 6 deletions src/scripts/services/ariaNgSettingService.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -207,15 +207,15 @@
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)) {
for (var i = 0; i < options.extendRpcServers.length; i++) {
var rpcSetting = options.extendRpcServers[i];

if (rpcSetting.secret) {
rpcSetting.secret = base64.decode(rpcSetting.secret);
rpcSetting.secret = ariaNgCommonService.base64Decode(rpcSetting.secret);
}
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -366,7 +366,7 @@
value = Math.max(parseInt(value), 0);
} else if (field === 'secret') {
if (value) {
value = base64.encode(value);
value = ariaNgCommonService.base64Encode(value);
}
}

Expand Down Expand Up @@ -439,7 +439,7 @@
newDefaultSetting = cloneRpcSetting(setting);

if (newDefaultSetting.secret) {
newDefaultSetting.secret = base64.encode(newDefaultSetting.secret);
newDefaultSetting.secret = ariaNgCommonService.base64Encode(newDefaultSetting.secret);
}
}

Expand Down

0 comments on commit edd3ac5

Please sign in to comment.