0.4.0 convex及界面修改

This commit is contained in:
liaibo
2026-02-01 08:47:40 +08:00
parent d1f055f51a
commit af92c4b149
636 changed files with 7522 additions and 1815 deletions
@@ -30,10 +30,18 @@ export async function POST(request: Request) {
if (!targetContent) {
return NextResponse.json({ error: "目标页面不存在或无权限" }, { status: 404 });
}
const targetMeta = await client.query(api.documents.getMeta, { id: targetId });
const currentBlocks = extractBlocksFromContent(targetContent.content);
const anchorId = (targetMeta as any)?.embed_default_block_id as string | null | undefined;
const anchorIndex =
typeof anchorId === "string" && anchorId.trim()
? currentBlocks.findIndex((b) => typeof b === "object" && b !== null && (b as any).id === anchorId)
: -1;
const insertIndex = anchorIndex >= 0 ? anchorIndex + 1 : currentBlocks.length;
const nextBlocks: Json[] = [
...currentBlocks,
...currentBlocks.slice(0, insertIndex),
{
id: randomUUID(),
type: "pageReference",
@@ -42,6 +50,7 @@ export async function POST(request: Request) {
title: sourceDoc.title ?? "无标题",
},
},
...currentBlocks.slice(insertIndex),
];
const payload: Json = composeContentWithBlocks(targetContent.content, nextBlocks);
@@ -27,6 +27,12 @@ export async function POST(request: Request) {
showStructure: options.showStructure,
protectEditing: options.protectEditing,
showWordCount: options.showWordCount,
collapseBacklinks: options.collapseBacklinks,
pageFont: options.pageFont,
layoutDensity: options.layoutDensity,
hideChildPages: options.hideChildPages,
showBlockRefCount: options.showBlockRefCount,
embedDefaultBlockId: typeof options.embedDefaultBlockId === "string" ? options.embedDefaultBlockId : null,
},
});
@@ -22,6 +22,8 @@ export async function POST(request: Request) {
wordCount: stats.wordCount,
characterCount: stats.characterCount,
blockCount: stats.blockCount,
todoTotal: stats.todoTotal,
todoDone: stats.todoDone,
});
return NextResponse.json({ ok: true });
@@ -0,0 +1,26 @@
import { NextResponse } from "next/server";
import { isConvexEnabled } from "@/lib/convex/enabled";
import { getAuthedConvexClient } from "@/lib/convex/route";
import { api } from "@/lib/convex/api";
type TemplatePayload = {
documentId: string;
isTemplate: boolean;
};
export async function POST(request: Request) {
if (isConvexEnabled()) {
const { documentId, isTemplate }: TemplatePayload = await request.json();
if (!documentId || typeof isTemplate !== "boolean") {
return NextResponse.json({ error: "缺少参数" }, { status: 400 });
}
const { client } = await getAuthedConvexClient();
await client.mutation(api.documents.setTemplate, { id: documentId, isTemplate });
return NextResponse.json({ ok: true });
}
return NextResponse.json({ error: "当前仅支持 Convex 模式" }, { status: 501 });
}