0.6 rust重构01

This commit is contained in:
lix-2026
2026-04-14 13:22:29 +08:00
parent 71fb1aee7e
commit 84a8454fa9
401 changed files with 5841 additions and 1512 deletions
@@ -1,16 +1,44 @@
import { notFound, redirect } from "next/navigation";
import { DocumentShell } from "@/components/editor/document-shell";
import type { PageOptionsState, DocumentStats } from "@/types/page-options";
import type { PageFont, PageLayoutDensity, PageOptionsState, DocumentStats } from "@/types/page-options";
import { isConvexEnabled } from "@/lib/convex/enabled";
import { getAuthedConvexClient } from "@/lib/convex/route";
import { api } from "@/lib/convex/api";
import { fetchDocumentMetaViaBridge } from "@/lib/documents/bridge-server";
interface DocumentPageProps {
params: Promise<{ id: string }>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
searchParams?: Promise<Record<string, any>>;
searchParams?: Promise<Record<string, string | string[] | undefined>>;
}
type DocumentMetaPayload = {
id: string;
workspace_id: string;
title: string | null;
updated_at: string | null;
can_edit?: boolean | null;
disable_download?: boolean | null;
disable_copy?: boolean | null;
wide_layout?: boolean | null;
use_small_text?: boolean | null;
show_heading_numbers?: boolean | null;
show_toc?: boolean | null;
show_structure?: boolean | null;
protect_editing?: boolean | null;
show_word_count?: boolean | null;
collapse_backlinks?: boolean | null;
page_font?: PageFont | null;
layout_density?: PageLayoutDensity | null;
hide_child_pages?: boolean | null;
show_block_ref_count?: boolean | null;
embed_default_block_id?: string | null;
word_count?: number | null;
character_count?: number | null;
block_count?: number | null;
todo_total?: number | null;
todo_total_count?: number | null;
todo_done?: number | null;
todo_done_count?: number | null;
};
export default async function DocumentPage({ params, searchParams }: DocumentPageProps) {
const { id } = await params;
const resolvedSearch = (await searchParams) ?? {};
@@ -18,14 +46,19 @@ export default async function DocumentPage({ params, searchParams }: DocumentPag
const openTableId = typeof openTableIdRaw === "string" ? openTableIdRaw : null;
if (isConvexEnabled()) {
const { client } = await getAuthedConvexClient();
const doc = await client.query(api.documents.getMeta, { id });
const workspaceIdRaw = resolvedSearch?.workspaceId;
const workspaceId = typeof workspaceIdRaw === "string" ? workspaceIdRaw : null;
const result = await fetchDocumentMetaViaBridge<DocumentMetaPayload>({
documentId: id,
workspaceId,
});
const doc = result?.doc;
if (!doc) {
notFound();
}
const readOnly = (doc as any).can_edit === false;
const disableDownload = Boolean((doc as any).disable_download);
const disableCopy = Boolean((doc as any).disable_copy);
const readOnly = doc.can_edit === false;
const disableDownload = Boolean(doc.disable_download);
const disableCopy = Boolean(doc.disable_copy);
const initialOptions: PageOptionsState = {
wideLayout: doc.wide_layout ?? false,
@@ -35,20 +68,20 @@ export default async function DocumentPage({ params, searchParams }: DocumentPag
showStructure: doc.show_structure ?? false,
protectEditing: doc.protect_editing ?? false,
showWordCount: doc.show_word_count ?? true,
collapseBacklinks: (doc as any).collapse_backlinks ?? false,
pageFont: (doc as any).page_font ?? "default",
layoutDensity: (doc as any).layout_density ?? "normal",
hideChildPages: (doc as any).hide_child_pages ?? false,
showBlockRefCount: (doc as any).show_block_ref_count ?? false,
embedDefaultBlockId: (doc as any).embed_default_block_id ?? null,
collapseBacklinks: doc.collapse_backlinks ?? false,
pageFont: doc.page_font ?? "default",
layoutDensity: doc.layout_density ?? "normal",
hideChildPages: doc.hide_child_pages ?? false,
showBlockRefCount: doc.show_block_ref_count ?? false,
embedDefaultBlockId: doc.embed_default_block_id ?? null,
};
const initialStats: DocumentStats = {
wordCount: doc.word_count ?? 0,
characterCount: doc.character_count ?? 0,
blockCount: doc.block_count ?? 0,
todoTotal: (doc as any).todo_total ?? (doc as any).todo_total_count ?? 0,
todoDone: (doc as any).todo_done ?? (doc as any).todo_done_count ?? 0,
todoTotal: doc.todo_total ?? doc.todo_total_count ?? 0,
todoDone: doc.todo_done ?? doc.todo_done_count ?? 0,
};
return (