推进 OPFS G-code 程序路径 helper

This commit is contained in:
2026-06-14 15:57:35 +08:00
parent a158f66071
commit d40a6422e8
5 changed files with 115 additions and 13 deletions

View File

@@ -3,9 +3,12 @@ import {
gcodeProgramPath,
machineIniPath,
parameterFilePath,
splitOpfsPath,
toolTablePath,
} from "./path-model.js";
const GCODE_PROGRAM_ROOT = ["linuxcnc", "gcode"];
const MACHINE_FILE_PATHS = {
ini: machineIniPath,
toolTable: toolTablePath,
@@ -43,6 +46,18 @@ export async function loadMachineTextFiles(machineId, options = {}) {
};
}
export function gcodeFilenameFromProgramPath(path) {
const parts = splitOpfsPath(path);
if (
parts.length !== 3 ||
parts[0] !== GCODE_PROGRAM_ROOT[0] ||
parts[1] !== GCODE_PROGRAM_ROOT[1]
) {
throw new Error(`Invalid G-code program OPFS path: ${path}`);
}
return parts[2];
}
export async function saveGcodeProgram(filename, text, options = {}) {
const path = gcodeProgramPath(filename);
await saveTextFile(path, text, options.storage);