From d51894fb75dbcaa306711268e0e28527f1dc0453 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 8 Jan 2026 23:44:31 -0500 Subject: [PATCH] add send to moonraker option --- src/kiri/app/export.js | 60 ++++++++++++++++++++++++-------------- src/kiri/app/init/input.js | 6 ++-- web/kiri/index.html | 38 +++++++++++++++++++----- web/kiri/lang/en.js | 11 ++++--- 4 files changed, 79 insertions(+), 36 deletions(-) diff --git a/src/kiri/app/export.js b/src/kiri/app/export.js index 999795ef..fa6604ef 100644 --- a/src/kiri/app/export.js +++ b/src/kiri/app/export.js @@ -192,6 +192,7 @@ function bindField(field, varname) { console.log('save', field, 'to', varname); localSet(varname, $(field).value.trim()); }; + $(field).onchange = $(field).onblur; } /** @@ -219,12 +220,7 @@ function exportGCodeDialog(gcode, sections, info, names) { codeproc = settings.device.gcodeProc, octo_host, octo_apik, - grid_host, - grid_apik, - grid_target, - grid_targets = {}, - grid_local, - grid_uuid; + octo_type; // join gcode array into a string gcode = gcode.join('\r\n') + '\r\n'; @@ -240,13 +236,18 @@ function exportGCodeDialog(gcode, sections, info, names) { {type:"application/octet-stream"}); } - function sendto_octoprint() { - if (!(octo_host && octo_apik)) return; + function printToHost() { + sendToHost(true); + } + + function sendToHost(start) { + if (!(octo_host && octo_apik && octo_type)) return; let form = new FormData(), ajax = new XMLHttpRequest(), host = octo_host.value.toLowerCase(), - apik = octo_apik.value; + apik = octo_apik.value, + type = octo_type.value; if (host.indexOf("http") !== 0) { api.show.alert("host missing protocol (http:// or https://)"); @@ -259,26 +260,37 @@ function exportGCodeDialog(gcode, sections, info, names) { localSet('octo-host', host.trim()); localSet('octo-apik', apik.trim()); + localSet('octo-type', type.trim()); filename = $('print-filename').value; form.append("file", getBlob(), filename+"."+fileext); + // moonraker upload params + // form.append("root", "gcodes"); // optional but recommended + // form.append("path", ""); // optional subfolder + if (start) form.append("print", "true"); // <-- auto-start ajax.onreadystatechange = function() { + console.log({ ajax_readyState: ajax.readyState }); if (ajax.readyState === 4) { let status = ajax.status; - api.stats.add(`ua_${api.mode.get_lower()}_print_octo_${status}`); + api.stats.add(`ua_${api.mode.get_lower()}_print_send_${status}`); if (status >= 200 && status < 300) { api.modal.hide(); } else { - api.show.alert("octoprint error\nstatus: "+status+"\nmessage: "+ajax.responseText); + api.show.alert("send error\nstatus: "+status+"\nmessage: "+ajax.responseText); } api.show.progress(0); } api.show.progress(0); }; - ajax.upload.addEventListener('progress', function(evt) { + ajax.upload.addEventListener('progress', (evt) => { + console.log({ ajax_progress: evt }); api.show.progress(evt.loaded/evt.total, "sending"); }); - ajax.open("POST", host+"/api/files/local"); + if (type === 'moonraker') { + ajax.open("POST", host + "/server/files/upload"); + } else { + ajax.open("POST", host + "/api/files/local"); + } if (apik) { ajax.setRequestHeader("X-Api-Key", apik); } @@ -349,6 +361,7 @@ function exportGCodeDialog(gcode, sections, info, names) { // persist fields when changed bindField('octo-host', 'octo-host'); bindField('octo-apik', 'octo-apik'); + bindField('octo-type', 'octo-type'); // in cam mode, show zip file option let downloadZip = $('print-zip'); @@ -550,21 +563,23 @@ function exportGCodeDialog(gcode, sections, info, names) { }) }; - // octoprint setup - $('send-to-octohead').style.display = octo ? '' : 'none'; - $('send-to-octoprint').style.display = octo ? '' : 'none'; + // remote host (klipper fluidd / octoprint) + $('send-remote-head').style.display = octo ? '' : 'none'; + $('send-remote-print').style.display = octo ? '' : 'none'; if (octo) try { - $('print-octoprint').onclick = sendto_octoprint; + $('send-remote').onclick = sendToHost; + $('print-remote').onclick = printToHost; octo_host = $('octo-host'); octo_apik = $('octo-apik'); + octo_type = $('octo-type'); if (MODE === MODES.CAM) { - $('send-to-octohead').style.display = 'none'; - $('send-to-octoprint').style.display = 'none'; + $('send-remote-head').style.display = 'none'; + $('send-remote-print').style.display = 'none'; } else { - $('send-to-octohead').style.display = ''; - $('send-to-octoprint').style.display = ''; + $('send-remote-head').style.display = ''; + $('send-remote-print').style.display = ''; } - // hide octoprint when hard-coded in the url + // hide remote host option when hard-coded in the url if (api.const.OCTO) { $('ophost').style.display = 'none'; $('opapik').style.display = 'none'; @@ -572,6 +587,7 @@ function exportGCodeDialog(gcode, sections, info, names) { } octo_host.value = localGet('octo-host') || ''; octo_apik.value = localGet('octo-apik') || ''; + octo_type.value = localGet('octo-type') || ''; } catch (e) { console.log(e) } // preview of the generated GCODE (first 64k max) diff --git a/src/kiri/app/init/input.js b/src/kiri/app/init/input.js index 05eef309..040e2dce 100644 --- a/src/kiri/app/init/input.js +++ b/src/kiri/app/init/input.js @@ -308,9 +308,9 @@ export function init_input() { spaceRandoX: newBoolean(LANG.op_spcx_s, preferences.booleanSave, {title:LANG.op_spcx_l, show:isBelt}), spaceLayout: newInput(LANG.op_spcr_s, {title:LANG.op_spcr_l, convert:toFloat, size:3, units}), _____: newGroup(LANG.xp_menu, $('prefs-xpo'), {inline: true}), - exportOcto: newBoolean(`OctoPrint`, preferences.booleanSave, {title:LANG.op_exop_l}), - exportThumb: newBoolean(`Thumbnail`, preferences.booleanSave, {modes:FDM}), - exportPreview: newBoolean(`Code Preview`, preferences.booleanSave), + exportPreview: newBoolean(LANG.op_excp_s, preferences.booleanSave, {title:LANG.op_excp_l}), + exportOcto: newBoolean(LANG.op_exop_s, preferences.booleanSave, {title:LANG.op_exop_l}), + exportThumb: newBoolean(LANG.op_exth_s, preferences.booleanSave, {title:LANG.op_exth_l, modes:FDM}), _____: newGroup(LANG.pt_menu, $('prefs-prt'), {inline}), detail: newSelect(LANG.pt_qual_s, {title: LANG.pt_qual_l, action: preferences.detailSave}, "detail"), healMesh: newBoolean(LANG.pt_heal_s, preferences.booleanSave, {title: LANG.pt_heal_l}), diff --git a/web/kiri/index.html b/web/kiri/index.html index c90fac76..46e2ca1c 100644 --- a/web/kiri/index.html +++ b/web/kiri/index.html @@ -678,19 +678,39 @@ - + -
-
+
+
-
-
+
+ + +
+
+ + +
+
+ + +
- + + +
+
+
-
this project needs your support! @@ -757,3 +777,7 @@
+
+ + +
diff --git a/web/kiri/lang/en.js b/web/kiri/lang/en.js index 77bd7e5e..a292599a 100644 --- a/web/kiri/lang/en.js +++ b/web/kiri/lang/en.js @@ -324,9 +324,12 @@ self.lang['en-us'] = { op_anim_l: ["animation mesh density","higher is more dense","takes more memory","and is slower"], op_mani_s: "manifold", op_mani_l: ["in stock indexed mode","use boolean visualiation","this is very expensive","and likely very slow"], - op_exgl_l: ["show Grid:Local devices in export dialog","includes Grid:Bots and OctoPrint plugins"], - op_exgh_l: ["legacy Grid:Host local network support"], - op_exop_l: ["legacy OctoPrint local network support","Grid:Space OctoPrint plugin recommended"], + op_exop_s: "remote host", + op_exop_l: ["enable sending files to remote hosts","moonraker = klipper","octoprint"], + op_excp_s: "code preview", + op_excp_l: ["show start of gcode","in export dialog"], + op_exth_s: "thumbnail", + op_exth_l: ["embed print thumbnail in gcode"], lo_menu: "layout", @@ -1014,7 +1017,7 @@ self.lang['en-us'] = { ex_gcpv: "gcode preview", ex_dwnl: "download", ex_bamb: "send to bambu", - ex_octo: "octoprint", + ex_octo: "remote host", ex_host: "host", ex_akey: "key", ex_rsnm: "resin used ML",