http request support GET method (for aria2 v1.15.1 and below)
This commit is contained in:
parent
492a115e2b
commit
c5e5fe49dc
|
@ -126,6 +126,8 @@ Enable Browser Notification=启用浏览器通知
|
||||||
Aria2 RPC Host=Aria2 RPC 主机
|
Aria2 RPC Host=Aria2 RPC 主机
|
||||||
Aria2 RPC Port=Aria2 RPC 端口
|
Aria2 RPC Port=Aria2 RPC 端口
|
||||||
Aria2 RPC Protocol=Aria2 RPC 协议
|
Aria2 RPC Protocol=Aria2 RPC 协议
|
||||||
|
Aria2 RPC Http Request Method=Aria2 RPC Http 请求方法
|
||||||
|
POST method only supports aria2 v1.15.2 and above.=POST 方法仅支持 Aria2 v1.15.2 及以上.
|
||||||
Aria2 RPC Secret Token=Aria2 RPC 密钥
|
Aria2 RPC Secret Token=Aria2 RPC 密钥
|
||||||
Aria2 RPC Address=Aria2 RPC 地址
|
Aria2 RPC Address=Aria2 RPC 地址
|
||||||
Global Stat Refresh Interval=全局状态刷新间隔
|
Global Stat Refresh Interval=全局状态刷新间隔
|
||||||
|
@ -160,6 +162,8 @@ Http=Http
|
||||||
Https=Https
|
Https=Https
|
||||||
WebSocket=WebSocket
|
WebSocket=WebSocket
|
||||||
WebSocket (Security)=WebSocket (安全)
|
WebSocket (Security)=WebSocket (安全)
|
||||||
|
POST=POST
|
||||||
|
GET=GET
|
||||||
Disabled=禁用
|
Disabled=禁用
|
||||||
Changes to the settings take effect after refreshing page.=设置将在页面刷新后生效.
|
Changes to the settings take effect after refreshing page.=设置将在页面刷新后生效.
|
||||||
Type is illegal!=类型错误!
|
Type is illegal!=类型错误!
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
rpcHost: '',
|
rpcHost: '',
|
||||||
rpcPort: '6800',
|
rpcPort: '6800',
|
||||||
protocol: 'http',
|
protocol: 'http',
|
||||||
|
httpMethod: 'POST',
|
||||||
secret: '',
|
secret: '',
|
||||||
globalStatRefreshInterval: 1000,
|
globalStatRefreshInterval: 1000,
|
||||||
downloadTaskRefreshInterval: 1000
|
downloadTaskRefreshInterval: 1000
|
||||||
|
|
|
@ -130,6 +130,8 @@
|
||||||
'Aria2 RPC Host': 'Aria2 RPC Host',
|
'Aria2 RPC Host': 'Aria2 RPC Host',
|
||||||
'Aria2 RPC Port': 'Aria2 RPC Port',
|
'Aria2 RPC Port': 'Aria2 RPC Port',
|
||||||
'Aria2 RPC Protocol': 'Aria2 RPC Protocol',
|
'Aria2 RPC Protocol': 'Aria2 RPC Protocol',
|
||||||
|
'Aria2 RPC Http Request Method': 'Aria2 RPC Http Request Method',
|
||||||
|
'POST method only supports aria2 v1.15.2 and above.': 'POST method only supports aria2 v1.15.2 and above.',
|
||||||
'Aria2 RPC Secret Token': 'Aria2 RPC Secret Token',
|
'Aria2 RPC Secret Token': 'Aria2 RPC Secret Token',
|
||||||
'Aria2 RPC Address': 'Aria2 RPC Address',
|
'Aria2 RPC Address': 'Aria2 RPC Address',
|
||||||
'Global Stat Refresh Interval': 'Global Stat Refresh Interval',
|
'Global Stat Refresh Interval': 'Global Stat Refresh Interval',
|
||||||
|
@ -164,6 +166,8 @@
|
||||||
'Https': 'Https',
|
'Https': 'Https',
|
||||||
'WebSocket': 'WebSocket',
|
'WebSocket': 'WebSocket',
|
||||||
'WebSocket (Security)': 'WebSocket (Security)',
|
'WebSocket (Security)': 'WebSocket (Security)',
|
||||||
|
'POST': 'POST',
|
||||||
|
'GET': 'GET',
|
||||||
'Disabled': 'Disabled',
|
'Disabled': 'Disabled',
|
||||||
'Changes to the settings take effect after refreshing page.': 'Changes to the settings take effect after refreshing page.',
|
'Changes to the settings take effect after refreshing page.': 'Changes to the settings take effect after refreshing page.',
|
||||||
'Type is illegal!': 'Type is illegal!',
|
'Type is illegal!': 'Type is illegal!',
|
||||||
|
|
|
@ -1,8 +1,53 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgSettingService', 'ariaNgLogService', function ($http, ariaNgSettingService, ariaNgLogService) {
|
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'base64', 'ariaNgSettingService', 'ariaNgLogService', function ($http, base64, ariaNgSettingService, ariaNgLogService) {
|
||||||
var rpcUrl = ariaNgSettingService.getJsonRpcUrl();
|
var rpcUrl = ariaNgSettingService.getJsonRpcUrl();
|
||||||
|
var method = ariaNgSettingService.getHttpMethod();
|
||||||
|
|
||||||
|
var getUrlWithQueryString = function (url, parameters) {
|
||||||
|
if (!url || url.length < 1) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryString = '';
|
||||||
|
|
||||||
|
for (var key in parameters) {
|
||||||
|
if (!parameters.hasOwnProperty(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var value = parameters[key];
|
||||||
|
|
||||||
|
if (value === null || angular.isUndefined(value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryString.length > 0) {
|
||||||
|
queryString += '&';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (angular.isObject(value) || angular.isArray(value)) {
|
||||||
|
value = angular.toJson(value);
|
||||||
|
value = base64.encode(value);
|
||||||
|
value = encodeURIComponent(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
queryString += key + '=' + value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryString.length < 1) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.indexOf('?') < 0) {
|
||||||
|
queryString = '?' + queryString;
|
||||||
|
} else {
|
||||||
|
queryString = '&' + queryString;
|
||||||
|
}
|
||||||
|
|
||||||
|
return url + queryString;
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
request: function (context) {
|
request: function (context) {
|
||||||
|
@ -12,10 +57,15 @@
|
||||||
|
|
||||||
var requestContext = {
|
var requestContext = {
|
||||||
url: rpcUrl,
|
url: rpcUrl,
|
||||||
method: 'POST',
|
method: method
|
||||||
data: context.requestBody
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (requestContext.method === 'POST') {
|
||||||
|
requestContext.data = context.requestBody;
|
||||||
|
} else if (requestContext.method === 'GET') {
|
||||||
|
requestContext.url = getUrlWithQueryString(requestContext.url, context.requestBody);
|
||||||
|
}
|
||||||
|
|
||||||
ariaNgLogService.debug('[aria2HttpRpcService.request] request start', requestContext);
|
ariaNgLogService.debug('[aria2HttpRpcService.request] request start', requestContext);
|
||||||
|
|
||||||
return $http(requestContext).success(function (data) {
|
return $http(requestContext).success(function (data) {
|
||||||
|
|
|
@ -182,6 +182,12 @@
|
||||||
setProtocol: function (value) {
|
setProtocol: function (value) {
|
||||||
setOption('protocol', value);
|
setOption('protocol', value);
|
||||||
},
|
},
|
||||||
|
getHttpMethod: function () {
|
||||||
|
return getOption('httpMethod');
|
||||||
|
},
|
||||||
|
setHttpMethod: function (value) {
|
||||||
|
setOption('httpMethod', value);
|
||||||
|
},
|
||||||
isUseWebSocket: function (protocol) {
|
isUseWebSocket: function (protocol) {
|
||||||
if (!protocol) {
|
if (!protocol) {
|
||||||
protocol = this.getProtocol();
|
protocol = this.getProtocol();
|
||||||
|
|
|
@ -116,6 +116,8 @@
|
||||||
ng-change="settingService.setRpcHost(context.settings.rpcHost)"/>
|
ng-change="settingService.setRpcHost(context.settings.rpcHost)"/>
|
||||||
<span class="input-group-addon" style="border-left: 0">:</span>
|
<span class="input-group-addon" style="border-left: 0">:</span>
|
||||||
<span class="input-group-addon" ng-bind="context.settings.rpcPort"></span>
|
<span class="input-group-addon" ng-bind="context.settings.rpcPort"></span>
|
||||||
|
<span class="input-group-addon">/</span>
|
||||||
|
<span class="input-group-addon">jsonrpc</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -144,6 +146,21 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row" ng-if="context.settings.protocol === 'http' || context.settings.protocol === 'https'">
|
||||||
|
<div class="setting-key setting-key-without-desc col-sm-4">
|
||||||
|
<span translate>Aria2 RPC Http Request Method</span>
|
||||||
|
<span class="asterisk">*</span>
|
||||||
|
<i class="icon-primary fa fa-question-circle" ng-tooltip-container="body" ng-tooltip-placement="top"
|
||||||
|
ng-tooltip="{{'POST method only supports aria2 v1.15.2 and above.' | translate}}"></i>
|
||||||
|
</div>
|
||||||
|
<div class="setting-value col-sm-8">
|
||||||
|
<select class="form-control" style="width: 100%;" ng-model="context.settings.httpMethod"
|
||||||
|
ng-change="settingService.setHttpMethod(context.settings.httpMethod)">
|
||||||
|
<option value="POST" translate>POST</option>
|
||||||
|
<option value="GET" translate>GET</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="setting-key setting-key-without-desc col-sm-4">
|
<div class="setting-key setting-key-without-desc col-sm-4">
|
||||||
<span translate>Aria2 RPC Secret Token</span>
|
<span translate>Aria2 RPC Secret Token</span>
|
||||||
|
|
Reference in a new issue