0.1.07 文件树拖拽与多思维导图

This commit is contained in:
liaibo
2026-01-08 06:28:14 +08:00
parent 9de2d69c55
commit 9af8b9e489
30 changed files with 817 additions and 410 deletions
@@ -59,13 +59,23 @@ async function ensureDocumentScaffold(id: string, title: string | null) {
}
async function copyMindmapIfExists(sourceId: string, targetId: string) {
const src = path.join(documentsBaseDir, sourceId, "mindmap.json");
const srcDir = path.join(documentsBaseDir, sourceId);
const destDir = path.join(documentsBaseDir, targetId);
const dest = path.join(destDir, "mindmap.json");
try {
const buf = await fs.readFile(src);
const entries = await fs.readdir(srcDir);
const mindmapFiles = entries.filter((name) => name === "mindmap.json" || /^mindmap-.+\\.json$/i.test(name));
if (mindmapFiles.length === 0) return;
await fs.mkdir(destDir, { recursive: true });
await fs.writeFile(dest, buf);
await Promise.all(
mindmapFiles.map(async (name) => {
try {
const buf = await fs.readFile(path.join(srcDir, name));
await fs.writeFile(path.join(destDir, name), buf);
} catch {
// ignore
}
}),
);
} catch {
// 源不存在则忽略
}
@@ -264,7 +274,8 @@ export async function POST(request: Request) {
} else {
siblingQuery.is("parent_id", null);
}
const { count: siblingCount = 0 } = await siblingQuery;
const { count: rawSiblingCount } = await siblingQuery;
const siblingCount = rawSiblingCount ?? 0;
const nextSortByParent = new Map<string | null, number>([[targetParentId, siblingCount]]);
const insertedDocs: Array<{ oldId: string; newId: string }> = [];
@@ -60,7 +60,8 @@ export async function POST(request: Request) {
siblingQuery.is("parent_id", null);
}
const { count: siblingCount = 0, error: countError } = await siblingQuery;
const { count: rawSiblingCount, error: countError } = await siblingQuery;
const siblingCount = rawSiblingCount ?? 0;
if (countError) {
return NextResponse.json({ error: countError.message }, { status: 500 });
@@ -86,7 +86,8 @@ async function handleCreateRequest(request: Request) {
siblingQuery.is("parent_id", null);
}
const { count: siblingCount = 0, error: countError } = await siblingQuery;
const { count: rawSiblingCount, error: countError } = await siblingQuery;
const siblingCount = rawSiblingCount ?? 0;
if (countError) {
return NextResponse.json({ error: countError.message }, { status: 500 });
@@ -19,13 +19,23 @@ async function ensureDocumentScaffold(id: string, title: string | null) {
}
async function copyMindmapIfExists(sourceId: string, targetId: string) {
const src = path.join(documentsBaseDir, sourceId, "mindmap.json");
const destDir = path.join(documentsBaseDir, targetId);
const dest = path.join(destDir, "mindmap.json");
try {
const buf = await fs.readFile(src);
const srcDir = path.join(documentsBaseDir, sourceId);
const destDir = path.join(documentsBaseDir, targetId);
const entries = await fs.readdir(srcDir);
const mindmapFiles = entries.filter((name) => name === "mindmap.json" || /^mindmap-.+\\.json$/i.test(name));
if (mindmapFiles.length === 0) return;
await fs.mkdir(destDir, { recursive: true });
await fs.writeFile(dest, buf);
await Promise.all(
mindmapFiles.map(async (name) => {
try {
const buf = await fs.readFile(path.join(srcDir, name));
await fs.writeFile(path.join(destDir, name), buf);
} catch {
// ignore
}
}),
);
} catch {
// 如果源不存在则忽略
}
@@ -68,7 +78,8 @@ export async function POST(request: Request) {
siblingQuery.is("parent_id", null);
}
const { count: siblingCount = 0, error: countError } = await siblingQuery;
const { count: rawSiblingCount, error: countError } = await siblingQuery;
const siblingCount = rawSiblingCount ?? 0;
if (countError) {
return NextResponse.json({ error: countError.message }, { status: 500 });
}