run_macro: use fetch instead of api.get for /api/file

api.get assumes JSON responses, but /api/file/<name> returns raw
gcode text. The await threw on response.json() and start_pause()
never fired. Use fetch directly and await response.text() to make
sure FileHandler.get's select_file side effect has been processed
before mach.start() runs.
This commit is contained in:
2026-05-01 16:29:25 +02:00
parent 1c69c0a157
commit b0712a5bf0

View File

@@ -580,7 +580,18 @@ module.exports = {
// right file.
if (file_name != this.state.selected) {
this.state.selected = file_name;
await api.get(`file/${encodeURIComponent(file_name)}`);
// GET /api/file/<name> returns gcode text (not JSON), so use
// fetch directly. The server's FileHandler.get sets
// state.selected as a side effect; we await the response
// before starting so mach.start() reads the right file.
const resp = await fetch(
`/api/file/${encodeURIComponent(file_name)}`,
{ cache: "no-cache" }
);
if (!resp.ok) {
throw new Error(`file fetch failed: ${resp.status}`);
}
await resp.text();
}
this.load();
if (this.state.macros[id].alert == true) {