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:
parent
8b5c8786b4
commit
345229c928
|
@ -2,7 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h3>Klippy Web API Test</h3>
|
<h3>Klippy Web API Test</h3>
|
||||||
|
@ -22,9 +22,12 @@
|
||||||
</form>
|
</form>
|
||||||
<br/>
|
<br/>
|
||||||
<form id="apiform">
|
<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
|
title="Should be a url for a http request, ie: /printer/objects/list, or a json-rpc registered
|
||||||
method name."/>
|
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"/>
|
<input type="submit" value="Send API Command"/>
|
||||||
<span id="apimethod">
|
<span id="apimethod">
|
||||||
<input type="radio" name="api_cmd_type" value="get" checked="true">GET
|
<input type="radio" name="api_cmd_type" value="get" checked="true">GET
|
||||||
|
|
|
@ -804,6 +804,7 @@ window.onload = () => {
|
||||||
'disabled', (api_type == 'websocket' || disable_transfer));
|
'disabled', (api_type == 'websocket' || disable_transfer));
|
||||||
$('.reqws').prop('disabled', (api_type == 'http'));
|
$('.reqws').prop('disabled', (api_type == 'http'));
|
||||||
$('#apimethod').prop('hidden', (api_type == "websocket"));
|
$('#apimethod').prop('hidden', (api_type == "websocket"));
|
||||||
|
$('#apiargs').prop('hidden', (api_type == "http"));
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#cbxFileTransfer').on('change', function () {
|
$('#cbxFileTransfer').on('change', function () {
|
||||||
|
@ -845,7 +846,7 @@ window.onload = () => {
|
||||||
// Send to a user defined endpoint and log the response
|
// Send to a user defined endpoint and log the response
|
||||||
if (api_type == 'http') {
|
if (api_type == 'http') {
|
||||||
let sendtype = $("input[type=radio][name=api_cmd_type]:checked").val();
|
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}
|
let settings = {url: url}
|
||||||
if (apikey != null)
|
if (apikey != null)
|
||||||
settings.headers = {"X-Api-Key": apikey};
|
settings.headers = {"X-Api-Key": apikey};
|
||||||
|
@ -868,12 +869,14 @@ window.onload = () => {
|
||||||
$.ajax(settings);
|
$.ajax(settings);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let cmd = $('#apiform [type=text]').val().split(',', 2);
|
let method = $('#apirequest').val().trim();
|
||||||
let method = cmd[0].trim();
|
let args = $('#apiargs').val();
|
||||||
if (cmd.length > 1) {
|
if (args != "") {
|
||||||
let args = cmd[1].trim();
|
try {
|
||||||
if (args.startsWith("{")) {
|
args = JSON.parse("{" + args + "}");
|
||||||
args = JSON.parse(args);
|
} catch (error) {
|
||||||
|
console.log("Unable to parse arguments");
|
||||||
|
return
|
||||||
}
|
}
|
||||||
json_rpc.call_method_with_kwargs(method, args)
|
json_rpc.call_method_with_kwargs(method, args)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
|
Loading…
Reference in New Issue