按建议,继续完成后续工作
结论:已新增 OPFS machine file store,支持 INI、tool table、parameter file 和 G-code 的纯文本保存/读取,并在 Node mock 与 Chromium smoke 中验证往返,不引入 CNC 文件格式语义。
This commit is contained in:
54
wasm-port/runtime/opfs/machine-file-store.js
Normal file
54
wasm-port/runtime/opfs/machine-file-store.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import { loadTextFile, saveTextFile } from "./file-service.js";
|
||||
import {
|
||||
gcodeProgramPath,
|
||||
machineIniPath,
|
||||
parameterFilePath,
|
||||
toolTablePath,
|
||||
} from "./path-model.js";
|
||||
|
||||
const MACHINE_FILE_PATHS = {
|
||||
ini: machineIniPath,
|
||||
toolTable: toolTablePath,
|
||||
parameters: parameterFilePath,
|
||||
};
|
||||
|
||||
export function machineFilePaths(machineId) {
|
||||
return {
|
||||
ini: machineIniPath(machineId),
|
||||
toolTable: toolTablePath(machineId),
|
||||
parameters: parameterFilePath(machineId),
|
||||
};
|
||||
}
|
||||
|
||||
export async function saveMachineTextFiles(machineId, files, options = {}) {
|
||||
if (files === null || typeof files !== "object" || Array.isArray(files)) {
|
||||
throw new Error("machine files must be a plain object.");
|
||||
}
|
||||
|
||||
const paths = machineFilePaths(machineId);
|
||||
for (const [name, pathFor] of Object.entries(MACHINE_FILE_PATHS)) {
|
||||
if (Object.hasOwn(files, name)) {
|
||||
await saveTextFile(pathFor(machineId), String(files[name]), options.storage);
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
export async function loadMachineTextFiles(machineId, options = {}) {
|
||||
const paths = machineFilePaths(machineId);
|
||||
return {
|
||||
ini: await loadTextFile(paths.ini, options.storage),
|
||||
toolTable: await loadTextFile(paths.toolTable, options.storage),
|
||||
parameters: await loadTextFile(paths.parameters, options.storage),
|
||||
};
|
||||
}
|
||||
|
||||
export async function saveGcodeProgram(filename, text, options = {}) {
|
||||
const path = gcodeProgramPath(filename);
|
||||
await saveTextFile(path, text, options.storage);
|
||||
return path;
|
||||
}
|
||||
|
||||
export async function loadGcodeProgram(filename, options = {}) {
|
||||
return loadTextFile(gcodeProgramPath(filename), options.storage);
|
||||
}
|
||||
Reference in New Issue
Block a user