test_client: add support for configuration file transfer
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
e0fb261c12
commit
829dd27aa2
|
@ -39,24 +39,31 @@
|
||||||
<div style="display: flex">
|
<div style="display: flex">
|
||||||
<input type="file" style="display:none" id="upload-file" />
|
<input type="file" style="display:none" id="upload-file" />
|
||||||
<div style="width: 10em">
|
<div style="width: 10em">
|
||||||
<button id="btnupload" class="toggleable" style="width: 9em">Upload GCode</button><br/><br/>
|
<button id="btnupload" class="toggleable" style="width: 9em">Upload File</button><br/><br/>
|
||||||
<button id="btndownload" class="toggleable" style="width: 9em">Download Gcode</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 Gcode</button><br/><br/>
|
<button id="btndelete" class="toggleable" style="width: 9em">Delete File</button><br/><br/>
|
||||||
<button id="btngetmetadata" style="width: 9em">Get Metadata</button>
|
<button id="btngetfiles" style="width: 9em">Refresh List</button>
|
||||||
<a id="hidden_link" href="#" hidden>hidden</a>
|
<a id="hidden_link" href="#" hidden>hidden</a>
|
||||||
</div>
|
</div>
|
||||||
<div style="width: 10em">
|
<div style="width: 10em">
|
||||||
<button id="btnstartprint" style="width: 9em">Start Print</button><br/><br/>
|
<button id="btnstartprint" style="width: 9em">Start Print</button><br/><br/>
|
||||||
<button id="btnpauseresume" style="width: 9em">Pause Print</button><br/><br/>
|
<button id="btnpauseresume" style="width: 9em">Pause Print</button><br/><br/>
|
||||||
<button id="btncancelprint" style="width: 9em">Cancel Print</button>
|
<button id="btncancelprint" style="width: 9em">Cancel Print</button><br/><br/>
|
||||||
|
<button id="btngetmetadata" style="width: 9em">Get Metadata</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<select id="filelist" size="8"></select>
|
<select id="filelist" size="8"></select>
|
||||||
</div>
|
</div>
|
||||||
|
<div id=filetype>
|
||||||
|
<input type="radio" name="file_type" value="gcodes" checked="true">GCodes<br/>
|
||||||
|
<input type="radio" name="file_type" value="config">Config Files
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
Progress: <progress id="progressbar" value="0" max="100"></progress>
|
Progress: <progress id="progressbar" value="0" max="100"></progress>
|
||||||
<span id="upload_progress">0%</span><br/><br/>
|
<span id="upload_progress">0%</span><br/><br/>
|
||||||
|
<button id="btnwritecfg" class="toggleable" style="width: 12em">Upload printer.cfg</button>
|
||||||
|
<button id="btngetcfg" class="toggleable" style="width: 12em">Download printer.cfg</button><br/><br/>
|
||||||
<button id="btnqueryendstops" style="width: 9em">Query Endstops</button>
|
<button id="btnqueryendstops" style="width: 9em">Query Endstops</button>
|
||||||
<button id="btnsubscribe" style="width: 9em">Post Subscription</button>
|
<button id="btnsubscribe" style="width: 9em">Post Subscription</button>
|
||||||
<button id="btngetsub" style="width: 9em">Get Subscription</button>
|
<button id="btngetsub" style="width: 9em">Get Subscription</button>
|
||||||
|
|
|
@ -96,6 +96,12 @@ var api = {
|
||||||
moonraker_log: {
|
moonraker_log: {
|
||||||
url: "/server/files/moonraker.log"
|
url: "/server/files/moonraker.log"
|
||||||
},
|
},
|
||||||
|
printer_cfg: {
|
||||||
|
url: "/server/files/config/printer.cfg"
|
||||||
|
},
|
||||||
|
included_cfg_files: {
|
||||||
|
url: "/server/files/config/include/"
|
||||||
|
},
|
||||||
|
|
||||||
// Machine APIs
|
// Machine APIs
|
||||||
reboot: {
|
reboot: {
|
||||||
|
@ -122,6 +128,8 @@ var paused = false;
|
||||||
var klippy_ready = false;
|
var klippy_ready = false;
|
||||||
var api_type = 'http';
|
var api_type = 'http';
|
||||||
var is_printing = false;
|
var is_printing = false;
|
||||||
|
var upload_location = "gcodes"
|
||||||
|
var file_list_type = "gcodes";
|
||||||
var json_rpc = new JsonRPC();
|
var json_rpc = new JsonRPC();
|
||||||
|
|
||||||
function round_float (value) {
|
function round_float (value) {
|
||||||
|
@ -188,6 +196,19 @@ function update_filelist(filelist) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_configlist(cfglist) {
|
||||||
|
$("#filelist").empty();
|
||||||
|
// Add base printer.cfg
|
||||||
|
$("#filelist").append(
|
||||||
|
"<option value='printer.cfg'>printer.cfg</option>");
|
||||||
|
for (let file of cfglist) {
|
||||||
|
let fname = "include/" + file.filename;
|
||||||
|
$("#filelist").append(
|
||||||
|
"<option value='" + fname + "'>" +
|
||||||
|
fname + "</option>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var last_progress = 0;
|
var last_progress = 0;
|
||||||
function update_progress(loaded, total) {
|
function update_progress(loaded, total) {
|
||||||
let progress = parseInt(loaded / total * 100);
|
let progress = parseInt(loaded / total * 100);
|
||||||
|
@ -215,11 +236,15 @@ function update_error(cmd, msg) {
|
||||||
|
|
||||||
//***********Websocket-Klipper API Functions (JSON-RPC)************/
|
//***********Websocket-Klipper API Functions (JSON-RPC)************/
|
||||||
function get_file_list() {
|
function get_file_list() {
|
||||||
json_rpc.call_method(api.file_list.method)
|
let args = {root: file_list_type}
|
||||||
|
json_rpc.call_method_with_kwargs(api.file_list.method, args)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
// result is an "ok" acknowledgment that the gcode has
|
// result is an "ok" acknowledgment that the gcode has
|
||||||
// been successfully processed
|
// been successfully processed
|
||||||
update_filelist(result);
|
if (file_list_type == "config")
|
||||||
|
update_configlist(result);
|
||||||
|
else
|
||||||
|
update_filelist(result);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
update_error(api.file_list.method, error);
|
update_error(api.file_list.method, error);
|
||||||
|
@ -585,7 +610,8 @@ json_rpc.register_method("notify_klippy_state_changed", handle_klippy_state);
|
||||||
function handle_file_list_changed(file_info) {
|
function handle_file_list_changed(file_info) {
|
||||||
// This event fires when a client has either added or removed
|
// This event fires when a client has either added or removed
|
||||||
// a gcode file.
|
// a gcode file.
|
||||||
update_filelist(file_info.filelist);
|
if (file_list_type == "gcodes")
|
||||||
|
update_filelist(file_info.filelist);
|
||||||
}
|
}
|
||||||
json_rpc.register_method("notify_filelist_changed", handle_file_list_changed);
|
json_rpc.register_method("notify_filelist_changed", handle_file_list_changed);
|
||||||
|
|
||||||
|
@ -807,6 +833,11 @@ window.onload = () => {
|
||||||
$('#apiargs').prop('hidden', (api_type == "http"));
|
$('#apiargs').prop('hidden', (api_type == "http"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('input[type=radio][name=file_type]').on('change', function() {
|
||||||
|
file_list_type = $(this).val();
|
||||||
|
get_file_list();
|
||||||
|
});
|
||||||
|
|
||||||
$('#cbxFileTransfer').on('change', function () {
|
$('#cbxFileTransfer').on('change', function () {
|
||||||
let disabled = false;
|
let disabled = false;
|
||||||
if (!$(this).is(":checked")) {
|
if (!$(this).is(":checked")) {
|
||||||
|
@ -901,6 +932,7 @@ window.onload = () => {
|
||||||
// Hidden file element's click is forwarded to the button
|
// Hidden file element's click is forwarded to the button
|
||||||
$('#btnupload').click(() => {
|
$('#btnupload').click(() => {
|
||||||
if (api_type == "http") {
|
if (api_type == "http") {
|
||||||
|
upload_location = file_list_type;
|
||||||
$('#upload-file').click();
|
$('#upload-file').click();
|
||||||
} else {
|
} else {
|
||||||
console.log("File Upload not supported over websocket")
|
console.log("File Upload not supported over websocket")
|
||||||
|
@ -922,6 +954,13 @@ window.onload = () => {
|
||||||
if (api_type == 'http') {
|
if (api_type == 'http') {
|
||||||
let fdata = new FormData();
|
let fdata = new FormData();
|
||||||
fdata.append("file", file);
|
fdata.append("file", file);
|
||||||
|
if (upload_location.startsWith("config")) {
|
||||||
|
fdata.append("root", "config");
|
||||||
|
if (upload_location == "config_main")
|
||||||
|
fdata.append("primary_config", "true");
|
||||||
|
} else {
|
||||||
|
fdata.append("root", upload_location);
|
||||||
|
}
|
||||||
let settings = {
|
let settings = {
|
||||||
url: api.upload.url,
|
url: api.upload.url,
|
||||||
data: fdata,
|
data: fdata,
|
||||||
|
@ -960,8 +999,20 @@ window.onload = () => {
|
||||||
let filename = $("#filelist").val();
|
let filename = $("#filelist").val();
|
||||||
if (filename) {
|
if (filename) {
|
||||||
if (api_type == 'http') {
|
if (api_type == 'http') {
|
||||||
// TODO: Must use oneshot token to download if API Key authorization is required
|
let url = api.gcode_files.url + filename;
|
||||||
let dl_url = "http://" + location.host + api.gcode_files.url + filename;
|
if (file_list_type == "config") {
|
||||||
|
url = api.included_cfg_files.url + filename;
|
||||||
|
if (filename.startsWith("include/")) {
|
||||||
|
url = api.included_cfg_files.url + filename.slice(8);
|
||||||
|
} else if (filename == "printer.cfg") {
|
||||||
|
url = api.printer_cfg.url;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Cannot download file: " + filename);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let dl_url = "http://" + location.host + url;
|
||||||
if (apikey != null) {
|
if (apikey != null) {
|
||||||
let settings = {
|
let settings = {
|
||||||
url: api.oneshot_token.url,
|
url: api.oneshot_token.url,
|
||||||
|
@ -988,8 +1039,18 @@ window.onload = () => {
|
||||||
let filename = $("#filelist").val();
|
let filename = $("#filelist").val();
|
||||||
if (filename) {
|
if (filename) {
|
||||||
if (api_type == 'http') {
|
if (api_type == 'http') {
|
||||||
|
let url = api.gcode_files.url + filename;
|
||||||
|
if (file_list_type == "config") {
|
||||||
|
url = api.included_cfg_files.url + filename;
|
||||||
|
if (filename.startsWith("include/")) {
|
||||||
|
url = api.included_cfg_files.url + filename.slice(8);
|
||||||
|
} else {
|
||||||
|
console.log("Cannot Delete printer.cfg");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
let settings = {
|
let settings = {
|
||||||
url: api.gcode_files.url + filename,
|
url: url,
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
success: (resp, status) => {
|
success: (resp, status) => {
|
||||||
console.log(resp);
|
console.log(resp);
|
||||||
|
@ -1079,6 +1140,53 @@ window.onload = () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Refresh File List
|
||||||
|
$("#btngetfiles").click(() =>{
|
||||||
|
if (api_type == 'http') {
|
||||||
|
let url = api.file_list.url + "?root=" + file_list_type;
|
||||||
|
let settings = {url: url};
|
||||||
|
if (apikey != null)
|
||||||
|
settings.headers = {"X-Api-Key": apikey};
|
||||||
|
$.get(settings, (resp, status) => {
|
||||||
|
console.log(resp);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
get_file_list();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#btnwritecfg').click(() => {
|
||||||
|
if (api_type == "http") {
|
||||||
|
upload_location = "config_main";
|
||||||
|
$('#upload-file').click();
|
||||||
|
} else {
|
||||||
|
console.log("File Upload not supported over websocket")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#btngetcfg').click(() => {
|
||||||
|
if (api_type == 'http') {
|
||||||
|
let dl_url = "http://" + location.host + api.printer_cfg.url;
|
||||||
|
if (apikey != null) {
|
||||||
|
let settings = {
|
||||||
|
url: api.oneshot_token.url,
|
||||||
|
headers: {"X-Api-Key": apikey}
|
||||||
|
};
|
||||||
|
$.get(settings, (resp, status) => {
|
||||||
|
let token = resp.result;
|
||||||
|
dl_url += "?token=" + token;
|
||||||
|
do_download(dl_url);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
do_download(dl_url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log("Get Log not supported over websocket")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$('#btnqueryendstops').click(() => {
|
$('#btnqueryendstops').click(() => {
|
||||||
if (api_type == 'http') {
|
if (api_type == 'http') {
|
||||||
let settings = {url: api.query_endstops.url};
|
let settings = {url: api.query_endstops.url};
|
||||||
|
|
Loading…
Reference in New Issue