推进 OPFS G-code 程序路径 helper
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user