support submit option data in array

This commit is contained in:
MaysWind 2018-10-07 23:37:26 +08:00
parent 27190d916d
commit 5c6cee7b42
2 changed files with 61 additions and 18 deletions

View file

@ -10,6 +10,7 @@
// [defaultValue: '',]
// [required: true|false,] //default: false
// [split: '',] //SUPPORT 'text' type
// [submitFormat: 'string|array'] //default: string, parameter 'split' is required
// [showCount: true|false,] //SUPPORT 'text' type, parameter 'split' is required, default: false
// [options: [],] //SUPPORT 'option' type
// [min: 0,] //SUPPORT 'integer', 'float'
@ -230,6 +231,7 @@
'header': {
type: 'text',
split: '\n',
submitFormat: 'array',
showCount: true
},
'save-cookies': {

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('aria2RpcService', ['$q', 'aria2RpcConstants', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2HttpRpcService', 'aria2WebSocketRpcService', function ($q, aria2RpcConstants, aria2RpcErrors, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2HttpRpcService, aria2WebSocketRpcService) {
angular.module('ariaNg').factory('aria2RpcService', ['$q', 'aria2RpcConstants', 'aria2RpcErrors', 'aria2AllOptions', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2HttpRpcService', 'aria2WebSocketRpcService', function ($q, aria2RpcConstants, aria2RpcErrors, aria2AllOptions, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2HttpRpcService, aria2WebSocketRpcService) {
var rpcImplementService = ariaNgSettingService.isCurrentRpcUseWebSocket() ? aria2WebSocketRpcService : aria2HttpRpcService;
var isConnected = false;
var secret = ariaNgSettingService.getCurrentRpcSecret();
@ -196,6 +196,57 @@
return context;
};
var buildRequestOptions = function (originalOptions, context) {
var options = angular.copy(originalOptions);
for (var optionName in options) {
if (!options.hasOwnProperty(optionName)) {
continue;
}
if (isOptionSubmitArray(options, optionName)) {
options[optionName] = buildArrayOption(options[optionName], aria2AllOptions[optionName]);
}
}
if (context && context.pauseOnAdded) {
options.pause = 'true';
}
return options;
};
var isOptionSubmitArray = function (options, optionName) {
if (!options[optionName] || !angular.isString(options[optionName])) {
return false;
}
if (!aria2AllOptions[optionName] || aria2AllOptions[optionName].submitFormat !== 'array') {
return false;
}
return true;
};
var buildArrayOption = function (option, optionSetting) {
var items = option.split(optionSetting.split);
var result = [];
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (!item) {
continue;
}
item = item.replace('\r', '');
result.push(item);
}
return result;
};
(function () {
registerEvent('onDownloadStart', onDownloadStartCallbacks);
registerEvent('onDownloadPause', onDownloadPauseCallbacks);
@ -230,11 +281,7 @@
},
addUri: function (context, returnContextOnly) {
var urls = context.task.urls;
var options = angular.copy(context.task.options);
if (context.pauseOnAdded) {
options.pause = 'true';
}
var options = buildRequestOptions(context.task.options, context);
return invoke(buildRequestContext('addUri', context, urls, options), !!returnContextOnly);
},
@ -255,21 +302,13 @@
},
addTorrent: function (context, returnContextOnly) {
var content = context.task.content;
var options = angular.copy(context.task.options);
if (context.pauseOnAdded) {
options.pause = 'true';
}
var options = buildRequestOptions(context.task.options, context);
return invoke(buildRequestContext('addTorrent', context, content, [], options), !!returnContextOnly);
},
addMetalink: function (context, returnContextOnly) {
var content = context.task.content;
var options = angular.copy(context.task.options);
if (context.pauseOnAdded) {
options.pause = 'true';
}
var options = buildRequestOptions(context.task.options, context);
return invoke(buildRequestContext('addMetalink', context, content, [], options), !!returnContextOnly);
},
@ -377,13 +416,15 @@
return invoke(buildRequestContext('getOption', context, context.gid), !!returnContextOnly);
},
changeOption: function (context, returnContextOnly) {
return invoke(buildRequestContext('changeOption', context, context.gid, context.options), !!returnContextOnly);
var options = buildRequestOptions(context.options, context);
return invoke(buildRequestContext('changeOption', context, context.gid, options), !!returnContextOnly);
},
getGlobalOption: function (context, returnContextOnly) {
return invoke(buildRequestContext('getGlobalOption', context), !!returnContextOnly);
},
changeGlobalOption: function (context, returnContextOnly) {
return invoke(buildRequestContext('changeGlobalOption', context, context.options), !!returnContextOnly);
var options = buildRequestOptions(context.options, context);
return invoke(buildRequestContext('changeGlobalOption', context, options), !!returnContextOnly);
},
getGlobalStat: function (context, returnContextOnly) {
return invoke(buildRequestContext('getGlobalStat', context), !!returnContextOnly);