推进 OPFS 会话快照清单能力
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
import { loadTextFile, saveTextFile } from "./file-service.js";
|
||||
import { sessionSnapshotPath } from "./path-model.js";
|
||||
import {
|
||||
gcodeProgramPath,
|
||||
machineIniPath,
|
||||
normalizeOpfsPath,
|
||||
parameterFilePath,
|
||||
sessionSnapshotPath,
|
||||
toolTablePath,
|
||||
} from "./path-model.js";
|
||||
|
||||
export const SESSION_SNAPSHOT_FORMAT = "linuxcnc-wasm-session-snapshot";
|
||||
export const SESSION_SNAPSHOT_VERSION = 1;
|
||||
@@ -10,6 +17,38 @@ function assertPlainObject(value, label) {
|
||||
}
|
||||
}
|
||||
|
||||
function optionalOpfsPath(value, label) {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof value !== "string") {
|
||||
throw new Error(`${label} must be a string.`);
|
||||
}
|
||||
return normalizeOpfsPath(value);
|
||||
}
|
||||
|
||||
export function createMachineSessionSnapshotPayload(machineId, options = {}) {
|
||||
assertPlainObject(options, "machine session snapshot options");
|
||||
const ini = optionalOpfsPath(options.iniOpfsPath, "INI OPFS path") ??
|
||||
machineIniPath(machineId, options.iniFilename);
|
||||
const parameters = optionalOpfsPath(options.parameterOpfsPath, "parameter OPFS path") ??
|
||||
parameterFilePath(machineId, options.parameterFilename);
|
||||
const toolTable = optionalOpfsPath(options.toolTableOpfsPath, "tool table OPFS path") ??
|
||||
toolTablePath(machineId, options.toolTableFilename);
|
||||
const gcode = optionalOpfsPath(options.gcodeOpfsPath, "G-code OPFS path") ??
|
||||
(options.gcodeFilename === undefined ? undefined : gcodeProgramPath(options.gcodeFilename));
|
||||
|
||||
return {
|
||||
machineId,
|
||||
files: {
|
||||
ini,
|
||||
parameters,
|
||||
toolTable,
|
||||
...(gcode === undefined ? {} : { gcode }),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function createSessionSnapshot(sessionId, payload, options = {}) {
|
||||
sessionSnapshotPath(sessionId, options.filename);
|
||||
assertPlainObject(payload, "snapshot payload");
|
||||
|
||||
Reference in New Issue
Block a user