support submit option data in array
This commit is contained in:
parent
27190d916d
commit
5c6cee7b42
|
@ -10,6 +10,7 @@
|
||||||
// [defaultValue: '',]
|
// [defaultValue: '',]
|
||||||
// [required: true|false,] //default: false
|
// [required: true|false,] //default: false
|
||||||
// [split: '',] //SUPPORT 'text' type
|
// [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
|
// [showCount: true|false,] //SUPPORT 'text' type, parameter 'split' is required, default: false
|
||||||
// [options: [],] //SUPPORT 'option' type
|
// [options: [],] //SUPPORT 'option' type
|
||||||
// [min: 0,] //SUPPORT 'integer', 'float'
|
// [min: 0,] //SUPPORT 'integer', 'float'
|
||||||
|
@ -230,6 +231,7 @@
|
||||||
'header': {
|
'header': {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
split: '\n',
|
split: '\n',
|
||||||
|
submitFormat: 'array',
|
||||||
showCount: true
|
showCount: true
|
||||||
},
|
},
|
||||||
'save-cookies': {
|
'save-cookies': {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'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 rpcImplementService = ariaNgSettingService.isCurrentRpcUseWebSocket() ? aria2WebSocketRpcService : aria2HttpRpcService;
|
||||||
var isConnected = false;
|
var isConnected = false;
|
||||||
var secret = ariaNgSettingService.getCurrentRpcSecret();
|
var secret = ariaNgSettingService.getCurrentRpcSecret();
|
||||||
|
@ -196,6 +196,57 @@
|
||||||
return context;
|
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 () {
|
(function () {
|
||||||
registerEvent('onDownloadStart', onDownloadStartCallbacks);
|
registerEvent('onDownloadStart', onDownloadStartCallbacks);
|
||||||
registerEvent('onDownloadPause', onDownloadPauseCallbacks);
|
registerEvent('onDownloadPause', onDownloadPauseCallbacks);
|
||||||
|
@ -230,11 +281,7 @@
|
||||||
},
|
},
|
||||||
addUri: function (context, returnContextOnly) {
|
addUri: function (context, returnContextOnly) {
|
||||||
var urls = context.task.urls;
|
var urls = context.task.urls;
|
||||||
var options = angular.copy(context.task.options);
|
var options = buildRequestOptions(context.task.options, context);
|
||||||
|
|
||||||
if (context.pauseOnAdded) {
|
|
||||||
options.pause = 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
return invoke(buildRequestContext('addUri', context, urls, options), !!returnContextOnly);
|
return invoke(buildRequestContext('addUri', context, urls, options), !!returnContextOnly);
|
||||||
},
|
},
|
||||||
|
@ -255,21 +302,13 @@
|
||||||
},
|
},
|
||||||
addTorrent: function (context, returnContextOnly) {
|
addTorrent: function (context, returnContextOnly) {
|
||||||
var content = context.task.content;
|
var content = context.task.content;
|
||||||
var options = angular.copy(context.task.options);
|
var options = buildRequestOptions(context.task.options, context);
|
||||||
|
|
||||||
if (context.pauseOnAdded) {
|
|
||||||
options.pause = 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
return invoke(buildRequestContext('addTorrent', context, content, [], options), !!returnContextOnly);
|
return invoke(buildRequestContext('addTorrent', context, content, [], options), !!returnContextOnly);
|
||||||
},
|
},
|
||||||
addMetalink: function (context, returnContextOnly) {
|
addMetalink: function (context, returnContextOnly) {
|
||||||
var content = context.task.content;
|
var content = context.task.content;
|
||||||
var options = angular.copy(context.task.options);
|
var options = buildRequestOptions(context.task.options, context);
|
||||||
|
|
||||||
if (context.pauseOnAdded) {
|
|
||||||
options.pause = 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
return invoke(buildRequestContext('addMetalink', context, content, [], options), !!returnContextOnly);
|
return invoke(buildRequestContext('addMetalink', context, content, [], options), !!returnContextOnly);
|
||||||
},
|
},
|
||||||
|
@ -377,13 +416,15 @@
|
||||||
return invoke(buildRequestContext('getOption', context, context.gid), !!returnContextOnly);
|
return invoke(buildRequestContext('getOption', context, context.gid), !!returnContextOnly);
|
||||||
},
|
},
|
||||||
changeOption: function (context, 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) {
|
getGlobalOption: function (context, returnContextOnly) {
|
||||||
return invoke(buildRequestContext('getGlobalOption', context), !!returnContextOnly);
|
return invoke(buildRequestContext('getGlobalOption', context), !!returnContextOnly);
|
||||||
},
|
},
|
||||||
changeGlobalOption: function (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) {
|
getGlobalStat: function (context, returnContextOnly) {
|
||||||
return invoke(buildRequestContext('getGlobalStat', context), !!returnContextOnly);
|
return invoke(buildRequestContext('getGlobalStat', context), !!returnContextOnly);
|
||||||
|
|
Reference in a new issue