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:
@@ -580,7 +580,18 @@ module.exports = {
|
|||||||
// right file.
|
// right file.
|
||||||
if (file_name != this.state.selected) {
|
if (file_name != this.state.selected) {
|
||||||
this.state.selected = file_name;
|
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();
|
this.load();
|
||||||
if (this.state.macros[id].alert == true) {
|
if (this.state.macros[id].alert == true) {
|
||||||
|
|||||||
Reference in New Issue
Block a user