mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-03 14:22:13 +08:00
feat: support static website
This commit is contained in:
53
frontend/scripts/save-demo.js
Normal file
53
frontend/scripts/save-demo.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import { config } from "dotenv";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { env } from "process";
|
||||
|
||||
export async function main() {
|
||||
const threadId = process.argv[2];
|
||||
const url = new URL(
|
||||
`http://localhost:2026/api/langgraph/threads/${threadId}/history`,
|
||||
);
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
limit: 10,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = (await response.json())[0];
|
||||
if (!data) {
|
||||
console.error("No data found");
|
||||
return;
|
||||
}
|
||||
|
||||
const title = data.values.title;
|
||||
|
||||
const rootPath = path.resolve(process.cwd(), "public/demo/threads", threadId);
|
||||
if (fs.existsSync(rootPath)) {
|
||||
fs.rmSync(rootPath, { recursive: true });
|
||||
}
|
||||
fs.mkdirSync(rootPath, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.resolve(rootPath, "thread.json"),
|
||||
JSON.stringify(data, null, 2),
|
||||
);
|
||||
const backendRootPath = path.resolve(
|
||||
process.cwd(),
|
||||
"../backend/.deer-flow/threads",
|
||||
threadId,
|
||||
);
|
||||
const outputsPath = path.resolve(backendRootPath, "user-data/outputs");
|
||||
if (fs.existsSync(outputsPath)) {
|
||||
fs.cpSync(outputsPath, path.resolve(rootPath, "user-data/outputs"), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
console.info(`Saved demo "${title}" to ${rootPath}`);
|
||||
}
|
||||
|
||||
config();
|
||||
main();
|
||||
Reference in New Issue
Block a user