test client: Add additional text box for Websocket API tests

Arguments are now specified in the secondary box, using JSON format without brackets.
This commit is contained in:
Arksine 2020-07-23 08:33:31 -04:00 committed by Eric Callahan
parent 8b5c8786b4
commit 345229c928
2 changed files with 15 additions and 9 deletions

View File

@ -2,7 +2,7 @@
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="/js/main.js?v=0.1.16" type="module"></script>
<script src="/js/main.js?v=0.1.17" type="module"></script>
</head>
<body>
<h3>Klippy Web API Test</h3>
@ -22,9 +22,12 @@
</form>
<br/>
<form id="apiform">
<input type="text" style="width: 30em" value="/printer/objects/list"
<input type="text" style="width: 30em" id="apirequest" name="apirequest" value="/printer/objects/list"
title="Should be a url for a http request, ie: /printer/objects/list, or a json-rpc registered
method name."/>
<input type="text" style="width: 20em" id="apiargs" name="apiargs"
title="Arguments for a websocket request. Arguments should be specified in as a JSON object, without
brackets." hidden/>
<input type="submit" value="Send API Command"/>
<span id="apimethod">
<input type="radio" name="api_cmd_type" value="get" checked="true">GET

View File

@ -804,6 +804,7 @@ window.onload = () => {
'disabled', (api_type == 'websocket' || disable_transfer));
$('.reqws').prop('disabled', (api_type == 'http'));
$('#apimethod').prop('hidden', (api_type == "websocket"));
$('#apiargs').prop('hidden', (api_type == "http"));
});
$('#cbxFileTransfer').on('change', function () {
@ -845,7 +846,7 @@ window.onload = () => {
// Send to a user defined endpoint and log the response
if (api_type == 'http') {
let sendtype = $("input[type=radio][name=api_cmd_type]:checked").val();
let url = $('#apiform [type=text]').val();
let url = $('#apirequest').val();
let settings = {url: url}
if (apikey != null)
settings.headers = {"X-Api-Key": apikey};
@ -868,12 +869,14 @@ window.onload = () => {
$.ajax(settings);
}
} else {
let cmd = $('#apiform [type=text]').val().split(',', 2);
let method = cmd[0].trim();
if (cmd.length > 1) {
let args = cmd[1].trim();
if (args.startsWith("{")) {
args = JSON.parse(args);
let method = $('#apirequest').val().trim();
let args = $('#apiargs').val();
if (args != "") {
try {
args = JSON.parse("{" + args + "}");
} catch (error) {
console.log("Unable to parse arguments");
return
}
json_rpc.call_method_with_kwargs(method, args)
.then((result) => {