test client: add support for websocket file delete

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-09-03 21:01:38 -04:00
parent ae49dfe8f2
commit 2a967303cb
2 changed files with 20 additions and 3 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.18" type="module"></script>
<script src="/js/main.js?v=0.1.19" type="module"></script>
</head>
<body>
<h3>Klippy Web API Test</h3>
@ -41,7 +41,7 @@
<div style="width: 10em">
<button id="btnupload" class="toggleable" style="width: 9em">Upload File</button><br/><br/>
<button id="btndownload" class="toggleable" style="width: 9em">Download File</button><br/><br/>
<button id="btndelete" class="toggleable" style="width: 9em">Delete File</button><br/><br/>
<button id="btndelete" style="width: 9em">Delete File</button><br/><br/>
<button id="btngetfiles" style="width: 9em">Refresh List</button>
<a id="hidden_link" href="#" hidden>hidden</a>
</div>

View File

@ -86,6 +86,9 @@ var api = {
delete: "server.files.delete_directory"
}
},
delete_file: {
method: "server.files.delete_file"
},
upload: {
url: "/server/files/upload"
},
@ -480,6 +483,19 @@ function get_metadata(file_name) {
});
}
function delete_file(file_path) {
json_rpc.call_method_with_kwargs(
api.delete_file.method, {'path': file_path})
.then((result) => {
// result is an "ok" acknowledgement that the
// print has started
console.log(result);
})
.catch((error) => {
update_error(api.delete_file.method, error);
});
}
function get_gcode_help() {
json_rpc.call_method(api.gcode_help.method)
.then((result) => {
@ -1046,7 +1062,8 @@ window.onload = () => {
settings.headers = {"X-Api-Key": apikey};
$.ajax(settings);
} else {
console.log("File Delete not supported over websocket")
let fname = file_list_type + "/" + filename;
delete_file(fname);
}
}
});