按建议,继续完成后续工作

结论:已新增 OPFS host-side 路径模型,覆盖 INI、tool table、parameter、G-code、preview cache 与 session snapshot 存储目标,并让 file-service 和浏览器 smoke 复用该模型;聚合 smoke 验证通过。
This commit is contained in:
2026-06-08 03:26:39 +08:00
parent 1f6d5a8e8b
commit 84bdc819b4
7 changed files with 147 additions and 27 deletions

View File

@@ -1,17 +1,4 @@
function splitPath(path) {
if (typeof path !== "string" || path.length === 0) {
throw new Error("OPFS path must be a non-empty relative path.");
}
if (path.startsWith("/") || path.includes("//")) {
throw new Error(`Invalid OPFS path: ${path}`);
}
const parts = path.split("/");
if (parts.some((part) => part === "." || part === ".." || part === "")) {
throw new Error(`Invalid OPFS path: ${path}`);
}
return parts;
}
import { splitOpfsPath } from "./path-model.js";
export async function getOpfsRoot(storage = globalThis.navigator?.storage) {
if (!storage?.getDirectory) {
@@ -21,7 +8,7 @@ export async function getOpfsRoot(storage = globalThis.navigator?.storage) {
}
export async function ensureParentDir(root, path) {
const parts = splitPath(path);
const parts = splitOpfsPath(path);
let current = root;
for (const part of parts.slice(0, -1)) {
current = await current.getDirectoryHandle(part, { create: true });
@@ -32,7 +19,7 @@ export async function ensureParentDir(root, path) {
export async function saveTextFile(path, text, storage) {
const root = await getOpfsRoot(storage);
const dir = await ensureParentDir(root, path);
const filename = splitPath(path).at(-1);
const filename = splitOpfsPath(path).at(-1);
const fileHandle = await dir.getFileHandle(filename, { create: true });
const writable = await fileHandle.createWritable();
await writable.write(text);
@@ -41,7 +28,7 @@ export async function saveTextFile(path, text, storage) {
export async function loadTextFile(path, storage) {
const root = await getOpfsRoot(storage);
const parts = splitPath(path);
const parts = splitOpfsPath(path);
let current = root;
for (const part of parts.slice(0, -1)) {
current = await current.getDirectoryHandle(part);