add aria2 rpc debug in debug console page

This commit is contained in:
MaysWind
2022-10-25 00:00:08 +08:00
parent 9bce4988ca
commit cd13b76773
5 changed files with 170 additions and 3 deletions

View File

@@ -268,6 +268,14 @@ Clear Logs=清空日志
Are you sure you want to clear debug logs?=您是否要清除调试日志?
Show Detail=显示详情
Log Detail=日志详情
Aria2 RPC Debug=Aria2 RPC 调试
Aria2 RPC Request Method=Aria2 RPC 请求方法
Aria2 RPC Request Parameters=Aria2 RPC 请求参数
Aria2 RPC Response=Aria2 RPC 响应
Execute=执行
RPC method is illegal!=RPC方法错误!
AriaNg does not support this RPC method!=AriaNg 不支持该RPC方法!
RPC request parameters are invalid!=RPC 请求参数无效!
Type is illegal!=类型错误!
Parameter is invalid!=请求参数无效!
Option value cannot be empty!=参数内容不能为空!

View File

@@ -268,6 +268,14 @@ Clear Logs=清除記錄
Are you sure you want to clear debug logs?=您是否要清除偵錯記錄?
Show Detail=顯示詳情
Log Detail=記錄詳情
Aria2 RPC Debug=Aria2 RPC 偵錯
Aria2 RPC Request Method=Aria2 RPC 要求方法
Aria2 RPC Request Parameters=Aria2 RPC 要求參數
Aria2 RPC Response=Aria2 RPC 回應
Execute=執行
RPC method is illegal!=RPC方法錯誤!
AriaNg does not support this RPC method!=AriaNg 不支援該RPC方法!
RPC request parameters are invalid!=RPC 要求參數無效!
Type is illegal!=類型錯誤!
Parameter is invalid!=要求參數無效!
Option value cannot be empty!=參數內容不能為空!

View File

@@ -273,6 +273,14 @@
'Are you sure you want to clear debug logs?': 'Are you sure you want to clear debug logs?',
'Show Detail': 'Show Detail',
'Log Detail': 'Log Detail',
'Aria2 RPC Debug': 'Aria2 RPC Debug',
'Aria2 RPC Request Method': 'Aria2 RPC Request Method',
'Aria2 RPC Request Parameters': 'Aria2 RPC Request Parameters',
'Aria2 RPC Response': 'Aria2 RPC Response',
'Execute': 'Execute',
'RPC method is illegal!': 'RPC method is illegal!',
'AriaNg does not support this RPC method!': 'AriaNg does not support this RPC method!',
'RPC request parameters are invalid!': 'RPC request parameters are invalid!',
'Type is illegal!': 'Type is illegal!',
'Parameter is invalid!': 'Parameter is invalid!',
'Option value cannot be empty!': 'Option value cannot be empty!',

View File

@@ -1,11 +1,15 @@
(function () {
'use strict';
angular.module('ariaNg').controller('AriaNgDebugController', ['$rootScope', '$scope', '$location', '$interval', '$timeout', 'ariaNgConstants', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', function ($rootScope, $scope, $location, $interval, $timeout, ariaNgConstants, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService) {
angular.module('ariaNg').controller('AriaNgDebugController', ['$rootScope', '$scope', '$location', '$interval', '$timeout', '$filter', 'ariaNgConstants', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgKeyboardService', 'ariaNgSettingService', 'aria2RpcService', function ($rootScope, $scope, $location, $interval, $timeout, $filter, ariaNgConstants, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgKeyboardService, ariaNgSettingService, aria2RpcService) {
var tabStatusItems = [
{
name: 'logs',
show: true
},
{
name: 'rpc',
show: true
}
];
var debugLogRefreshPromise = null;
@@ -22,6 +26,21 @@
return items;
};
var loadAria2RPCMethods = function () {
if ($scope.context.availableRpcMethods && $scope.context.availableRpcMethods.length) {
return;
}
return aria2RpcService.listMethods({
silent: false,
callback: function (response) {
if (response.success) {
$scope.context.availableRpcMethods = response.data;
}
}
});
};
$scope.context = {
currentTab: 'logs',
logMaxCount: ariaNgConstants.cachedDebugLogsLimit,
@@ -30,7 +49,11 @@
logListDisplayOrder: 'time:desc',
logLevelFilter: 'DEBUG',
logs: [],
currentLog: null
currentLog: null,
availableRpcMethods: [],
rpcRequestMethod: '',
rpcRequestParameters: '{}',
rpcResponse: null
};
$scope.enableDebugMode = function () {
@@ -38,6 +61,10 @@
};
$scope.changeTab = function (tabName) {
if (tabName === 'rpc') {
$rootScope.loadPromise = loadAria2RPCMethods();
}
$scope.context.currentTab = tabName;
};
@@ -123,6 +150,74 @@
$scope.context.currentLog = null;
});
$scope.executeAria2Method = function () {
if (!$scope.context.rpcRequestMethod || $scope.context.rpcRequestMethod.indexOf('.') < 0) {
ariaNgCommonService.showError('RPC method is illegal!');
return;
}
var methodNameParts = $scope.context.rpcRequestMethod.split('.');
if (methodNameParts.length !== 2) {
ariaNgCommonService.showError('RPC method is illegal!');
return;
}
var methodName = methodNameParts[1];
if (!angular.isFunction(aria2RpcService[methodName])) {
ariaNgCommonService.showError('AriaNg does not support this RPC method!');
return;
}
var context = {
silent: false,
callback: function (response) {
if (response) {
$scope.context.rpcResponse = $filter('json')(response.data);
} else {
$scope.context.rpcResponse = $filter('json')(response);
}
}
};
var parameters = {};
try {
parameters = angular.fromJson($scope.context.rpcRequestParameters);
} catch (ex) {
ariaNgLogService.error('[AriaNgDebugController.executeAria2Method] failed to parse request parameters: ' + $scope.context.rpcRequestParameters, ex);
ariaNgCommonService.showError('RPC request parameters are invalid!');
return;
}
for (var key in parameters) {
if (!parameters.hasOwnProperty(key) || key === 'silent' || key === 'callback') {
continue;
}
context[key] = parameters[key];
}
return aria2RpcService[methodName](context);
};
$scope.requestParametersTextboxKeyDown = function (event) {
if (!ariaNgSettingService.getKeyboardShortcuts()) {
return;
}
if (ariaNgKeyboardService.isCtrlEnterPressed(event) && $scope.executeMethodForm.$valid) {
if (event.preventDefault) {
event.preventDefault();
}
$scope.executeAria2Method();
return false;
}
};
$scope.$on('$destroy', function () {
if (debugLogRefreshPromise) {
$interval.cancel(debugLogRefreshPromise);

View File

@@ -1,9 +1,12 @@
<section class="content no-padding ng-cloak" ng-if="enableDebugMode()">
<section class="content no-padding ng-cloak" ng-show="enableDebugMode()">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li ng-class="{'active': context.currentTab === 'logs'}">
<a class="pointer-cursor" ng-click="changeTab('logs')" ng-bind="('format.debug.latest-logs' | translate: {count: context.logMaxCount})">Latest Logs</a>
</li>
<li ng-class="{'active': context.currentTab === 'rpc'}">
<a class="pointer-cursor" ng-click="changeTab('rpc')" translate>Aria2 RPC Debug</a>
</li>
</ul>
<div class="tab-content no-padding">
@@ -82,6 +85,51 @@
</div>
</div>
</div>
<div class="tab-pane" ng-class="{'active': context.currentTab === 'rpc'}">
<form name="executeMethodForm" ng-submit="executeAria2Method()" novalidate>
<div class="settings-table striped hoverable">
<div class="row">
<div class="setting-key setting-key-without-desc col-sm-4">
<span translate>Aria2 RPC Request Method</span>
</div>
<div class="setting-value col-sm-8">
<select name="method" class="form-control" style="width: 100%;" ng-required="true"
ng-model="context.rpcRequestMethod"
ng-options="method as method for method in context.availableRpcMethods">
</select>
</div>
</div>
<div class="row">
<div class="setting-key setting-key-without-desc col-sm-4">
<span translate>Aria2 RPC Request Parameters</span>
</div>
<div class="setting-value col-sm-8">
<textarea name="parameters" class="form-control" rows="6" ng-required="true"
ng-keydown="requestParametersTextboxKeyDown($event)"
ng-model="context.rpcRequestParameters"></textarea>
</div>
</div>
<div class="row">
<div class="setting-key setting-key-without-desc col-sm-4">
<span translate>Aria2 RPC Response</span>
</div>
<div class="setting-value col-sm-8">
<textarea class="form-control" rows="10" readonly="readonly"
ng-model="context.rpcResponse"></textarea>
</div>
</div>
<div class="row">
<div class="setting-key setting-key-without-desc col-sm-4"></div>
<div class="setting-value col-sm-8">
<button class="btn btn-sm btn-primary" ng-disabled="!executeMethodForm.$valid"
ng-click="executeAria2Method()" promise-btn>
<span translate>Execute</span>
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>