diff --git a/src/langs/zh_CN.txt b/src/langs/zh_CN.txt index 67a745e..48d0805 100644 --- a/src/langs/zh_CN.txt +++ b/src/langs/zh_CN.txt @@ -126,6 +126,8 @@ Enable Browser Notification=启用浏览器通知 Aria2 RPC Host=Aria2 RPC 主机 Aria2 RPC Port=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 Address=Aria2 RPC 地址 Global Stat Refresh Interval=全局状态刷新间隔 @@ -160,6 +162,8 @@ Http=Http Https=Https WebSocket=WebSocket WebSocket (Security)=WebSocket (安全) +POST=POST +GET=GET Disabled=禁用 Changes to the settings take effect after refreshing page.=设置将在页面刷新后生效. Type is illegal!=类型错误! diff --git a/src/scripts/config/constants.js b/src/scripts/config/constants.js index d851cf9..8bfdb0d 100644 --- a/src/scripts/config/constants.js +++ b/src/scripts/config/constants.js @@ -23,6 +23,7 @@ rpcHost: '', rpcPort: '6800', protocol: 'http', + httpMethod: 'POST', secret: '', globalStatRefreshInterval: 1000, downloadTaskRefreshInterval: 1000 diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index 76638a6..7ed9f2d 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -130,6 +130,8 @@ 'Aria2 RPC Host': 'Aria2 RPC Host', 'Aria2 RPC Port': 'Aria2 RPC Port', '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 Address': 'Aria2 RPC Address', 'Global Stat Refresh Interval': 'Global Stat Refresh Interval', @@ -164,6 +166,8 @@ 'Https': 'Https', 'WebSocket': 'WebSocket', 'WebSocket (Security)': 'WebSocket (Security)', + '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!', diff --git a/src/scripts/services/aria2HttpRpcService.js b/src/scripts/services/aria2HttpRpcService.js index c01d725..c247dfb 100644 --- a/src/scripts/services/aria2HttpRpcService.js +++ b/src/scripts/services/aria2HttpRpcService.js @@ -1,8 +1,53 @@ (function () { '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 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 { request: function (context) { @@ -12,10 +57,15 @@ var requestContext = { url: rpcUrl, - method: 'POST', - data: context.requestBody + method: method }; + 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); return $http(requestContext).success(function (data) { diff --git a/src/scripts/services/ariaNgSettingService.js b/src/scripts/services/ariaNgSettingService.js index 9486dc5..7a28493 100644 --- a/src/scripts/services/ariaNgSettingService.js +++ b/src/scripts/services/ariaNgSettingService.js @@ -182,6 +182,12 @@ setProtocol: function (value) { setOption('protocol', value); }, + getHttpMethod: function () { + return getOption('httpMethod'); + }, + setHttpMethod: function (value) { + setOption('httpMethod', value); + }, isUseWebSocket: function (protocol) { if (!protocol) { protocol = this.getProtocol(); diff --git a/src/views/settings-ariang.html b/src/views/settings-ariang.html index e5ed1b6..ccfc892 100644 --- a/src/views/settings-ariang.html +++ b/src/views/settings-ariang.html @@ -116,6 +116,8 @@ ng-change="settingService.setRpcHost(context.settings.rpcHost)"/> : + / + jsonrpc @@ -144,6 +146,21 @@ +
+
+ Aria2 RPC Http Request Method + * + +
+
+ +
+
Aria2 RPC Secret Token