Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel
2026-06-03 11:40:38 +08:00
parent 3ee395b3bf
commit 8564a03a11

View File

@@ -22,26 +22,17 @@ function newSessionId(): string {
return (window as any).Lute ? (window as any).Lute.NewNodeID() : Date.now().toString(36);
}
async function readTextFile(path: string): Promise<string | null> {
async function readJsonFile(path: string): Promise<any | null> {
try {
var r = await fetchSyncPost("/api/file/getFile", {path: path}) as any;
console.log("[SS] getFile full response:", JSON.stringify(r));
if (!r || r.code !== 0 || !r.data || r.data === null) {
return null;
}
return r.data;
// getFile 返回的是文件内容本身,不是 {code, data} 包装
if (!r) { return null; }
return r;
} catch (e) {
console.log("[SS] readText error:", path, e);
return null;
}
}
async function readJsonFile(path: string): Promise<any | null> {
var text = await readTextFile(path);
if (!text) { console.log("[SS] readJson null, path:", path); return null; }
try { return JSON.parse(text); } catch (e) { console.log("[SS] readJson parse err:", path, e); return null; }
}
async function writeJsonFile(path: string, data: any): Promise<void> {
var content = JSON.stringify(data, null, 2);
var fileName = path.split("/").pop() || "file.json";