feat: 收口文档桥接与 OnlyOffice/Sidebar 回归
- 为 documents.save/meta/content、blocks.patch 与 sidebar.dataset.list 补齐 Rust 协议映射、共享契约与桥接执行器 - 对齐 BlockNote、Mindmap、OnlyOffice 的保存/路由元信息,并补真实浏览器回归脚本与 OnlyOffice 部署基线 - 忽略 Rust 本地构建产物与 Harness 调试状态文件,避免临时产物进入仓库历史
This commit is contained in:
+4
@@ -10,6 +10,7 @@
|
||||
|
||||
import type * as _utils_attachmentExtract from "../_utils/attachmentExtract.js";
|
||||
import type * as _utils_auth from "../_utils/auth.js";
|
||||
import type * as _utils_documentRecord from "../_utils/documentRecord.js";
|
||||
import type * as _utils_documentTree from "../_utils/documentTree.js";
|
||||
import type * as _utils_id from "../_utils/id.js";
|
||||
import type * as _utils_ingestJobs from "../_utils/ingestJobs.js";
|
||||
@@ -40,6 +41,7 @@ import type * as pages from "../pages.js";
|
||||
import type * as ping from "../ping.js";
|
||||
import type * as recents from "../recents.js";
|
||||
import type * as references from "../references.js";
|
||||
import type * as sidebar from "../sidebar.js";
|
||||
import type * as tables from "../tables.js";
|
||||
import type * as users from "../users.js";
|
||||
import type * as workspaces from "../workspaces.js";
|
||||
@@ -53,6 +55,7 @@ import type {
|
||||
declare const fullApi: ApiFromModules<{
|
||||
"_utils/attachmentExtract": typeof _utils_attachmentExtract;
|
||||
"_utils/auth": typeof _utils_auth;
|
||||
"_utils/documentRecord": typeof _utils_documentRecord;
|
||||
"_utils/documentTree": typeof _utils_documentTree;
|
||||
"_utils/id": typeof _utils_id;
|
||||
"_utils/ingestJobs": typeof _utils_ingestJobs;
|
||||
@@ -83,6 +86,7 @@ declare const fullApi: ApiFromModules<{
|
||||
ping: typeof ping;
|
||||
recents: typeof recents;
|
||||
references: typeof references;
|
||||
sidebar: typeof sidebar;
|
||||
tables: typeof tables;
|
||||
users: typeof users;
|
||||
workspaces: typeof workspaces;
|
||||
|
||||
@@ -445,14 +445,32 @@ export const getContent = query({
|
||||
}
|
||||
|
||||
if (doc.user_id === userId) {
|
||||
return { content: doc.content ?? null };
|
||||
return {
|
||||
content: doc.content ?? null,
|
||||
revision: doc.content_revision ?? 0,
|
||||
conflict_detection_key:
|
||||
doc.content_conflict_key ??
|
||||
`${args.id}:${doc.content_revision ?? 0}`,
|
||||
};
|
||||
}
|
||||
if (doc.access_scope === "public") {
|
||||
return { content: doc.content ?? null };
|
||||
return {
|
||||
content: doc.content ?? null,
|
||||
revision: doc.content_revision ?? 0,
|
||||
conflict_detection_key:
|
||||
doc.content_conflict_key ??
|
||||
`${args.id}:${doc.content_revision ?? 0}`,
|
||||
};
|
||||
}
|
||||
const perm = (await resolveSharePermission(ctx, doc, userId)) ?? (await resolveGroupSharePermission(ctx, doc, userId));
|
||||
if (!perm) return null;
|
||||
return { content: doc.content ?? null };
|
||||
return {
|
||||
content: doc.content ?? null,
|
||||
revision: doc.content_revision ?? 0,
|
||||
conflict_detection_key:
|
||||
doc.content_conflict_key ??
|
||||
`${args.id}:${doc.content_revision ?? 0}`,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -462,7 +480,13 @@ export const getContentForIngest = internalQuery({
|
||||
const doc = await getCanonicalDocumentByBusinessId(ctx, args.id);
|
||||
if (!doc) return null;
|
||||
if (doc.user_id !== args.userId) return null;
|
||||
return { content: doc.content ?? null };
|
||||
return {
|
||||
content: doc.content ?? null,
|
||||
revision: doc.content_revision ?? 0,
|
||||
conflict_detection_key:
|
||||
doc.content_conflict_key ??
|
||||
`${args.id}:${doc.content_revision ?? 0}`,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -791,6 +815,8 @@ export const create = mutation({
|
||||
parent_id: args.parentId,
|
||||
title,
|
||||
content,
|
||||
content_revision: 0,
|
||||
content_conflict_key: `${args.id}:0`,
|
||||
raw_text: rawText,
|
||||
access_scope: args.accessScope,
|
||||
sort_order: sortOrder,
|
||||
@@ -837,7 +863,12 @@ export const create = mutation({
|
||||
});
|
||||
|
||||
export const updateContent = mutation({
|
||||
args: { id: v.string(), content: v.any() },
|
||||
args: {
|
||||
id: v.string(),
|
||||
content: v.any(),
|
||||
expectedRevision: v.optional(v.union(v.number(), v.null())),
|
||||
conflictDetectionKey: v.optional(v.union(v.string(), v.null())),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const userId = await requireUserId(ctx);
|
||||
|
||||
@@ -851,14 +882,48 @@ export const updateContent = mutation({
|
||||
const perm = (await resolveSharePermission(ctx, doc, userId)) ?? (await resolveGroupSharePermission(ctx, doc, userId));
|
||||
if (perm !== "edit") throw new Error("无权限");
|
||||
}
|
||||
const currentRevision = doc.content_revision ?? 0;
|
||||
const currentConflictDetectionKey =
|
||||
doc.content_conflict_key ??
|
||||
`${args.id}:${currentRevision}`;
|
||||
|
||||
if (
|
||||
typeof args.expectedRevision === "number" &&
|
||||
Number.isInteger(args.expectedRevision) &&
|
||||
args.expectedRevision >= 0 &&
|
||||
args.expectedRevision !== currentRevision
|
||||
) {
|
||||
throw new Error("正文内容已变更,请刷新后重试");
|
||||
}
|
||||
|
||||
if (
|
||||
typeof args.conflictDetectionKey === "string" &&
|
||||
args.conflictDetectionKey.trim() &&
|
||||
args.conflictDetectionKey.trim() !== currentConflictDetectionKey
|
||||
) {
|
||||
throw new Error("正文冲突检测失败,请刷新后重试");
|
||||
}
|
||||
const ts = nowIso();
|
||||
const rawText = extractTextFromDocumentContent(args.content);
|
||||
await ctx.db.patch(doc._id, { content: args.content, raw_text: rawText, updated_at: ts });
|
||||
const nextRevision = currentRevision + 1;
|
||||
const nextConflictDetectionKey = `${args.id}:${nextRevision}`;
|
||||
await ctx.db.patch(doc._id, {
|
||||
content: args.content,
|
||||
content_revision: nextRevision,
|
||||
content_conflict_key: nextConflictDetectionKey,
|
||||
raw_text: rawText,
|
||||
updated_at: ts,
|
||||
});
|
||||
|
||||
// 说明:在 Convex 模式下,把"自动入库/LightRAG 触发"迁到 Convex jobs/actions。
|
||||
// 采用 debounce,避免频繁保存时触发过多任务。
|
||||
await enqueueIngestDocumentJob(ctx, { userId: doc.user_id, documentId: args.id, debounceMs: 1500 });
|
||||
return { ok: true, updated_at: ts };
|
||||
return {
|
||||
ok: true,
|
||||
updated_at: ts,
|
||||
revision: nextRevision,
|
||||
conflict_detection_key: nextConflictDetectionKey,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -138,7 +138,15 @@ export const put = mutation({
|
||||
const payload = args.data ?? defaultMindmapData;
|
||||
|
||||
if (existing && existing.deleted_at == null && args.createOnly) {
|
||||
return { ok: true, created: false, skipped: true, updated_at: existing.updated_at ?? null };
|
||||
return {
|
||||
ok: true,
|
||||
created: false,
|
||||
skipped: true,
|
||||
workspace_id: doc.workspace_id,
|
||||
document_id: args.docId,
|
||||
mindmap_id: mindmapId,
|
||||
updated_at: existing.updated_at ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
if (existing) {
|
||||
@@ -149,7 +157,15 @@ export const put = mutation({
|
||||
deleted_by: null,
|
||||
});
|
||||
await enqueueIngestMindmapJob(ctx, { userId, docId: args.docId, mindmapId, debounceMs: 1500 });
|
||||
return { ok: true, created: false, skipped: false, updated_at: ts };
|
||||
return {
|
||||
ok: true,
|
||||
created: false,
|
||||
skipped: false,
|
||||
workspace_id: doc.workspace_id,
|
||||
document_id: args.docId,
|
||||
mindmap_id: mindmapId,
|
||||
updated_at: ts,
|
||||
};
|
||||
}
|
||||
|
||||
await ctx.db.insert("mindmaps", {
|
||||
@@ -166,7 +182,15 @@ export const put = mutation({
|
||||
});
|
||||
|
||||
await enqueueIngestMindmapJob(ctx, { userId, docId: args.docId, mindmapId, debounceMs: 1500 });
|
||||
return { ok: true, created: true, skipped: false, updated_at: ts };
|
||||
return {
|
||||
ok: true,
|
||||
created: true,
|
||||
skipped: false,
|
||||
workspace_id: doc.workspace_id,
|
||||
document_id: args.docId,
|
||||
mindmap_id: mindmapId,
|
||||
updated_at: ts,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -185,12 +209,26 @@ export const softDelete = mutation({
|
||||
|
||||
if (!existing) {
|
||||
// 兼容:不存在也视为成功
|
||||
return { ok: true, moved: 0 };
|
||||
return {
|
||||
ok: true,
|
||||
moved: 0,
|
||||
workspace_id: null,
|
||||
document_id: args.docId,
|
||||
mindmap_id: mindmapId,
|
||||
deleted_at: null,
|
||||
};
|
||||
}
|
||||
|
||||
if (existing.deleted_at != null) {
|
||||
// 已在垃圾桶:保持幂等,避免重复删除导致 updated_at 抖动/重复调度
|
||||
return { ok: true, moved: 0, deleted_at: existing.deleted_at };
|
||||
return {
|
||||
ok: true,
|
||||
moved: 0,
|
||||
workspace_id: existing.workspace_id,
|
||||
document_id: args.docId,
|
||||
mindmap_id: mindmapId,
|
||||
deleted_at: existing.deleted_at,
|
||||
};
|
||||
}
|
||||
|
||||
const ts = nowIso();
|
||||
@@ -204,7 +242,14 @@ export const softDelete = mutation({
|
||||
mindmapId,
|
||||
deletedAt: ts,
|
||||
});
|
||||
return { ok: true, moved: 1, deleted_at: ts };
|
||||
return {
|
||||
ok: true,
|
||||
moved: 1,
|
||||
workspace_id: existing.workspace_id,
|
||||
document_id: args.docId,
|
||||
mindmap_id: mindmapId,
|
||||
deleted_at: ts,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -272,7 +317,13 @@ export const restore = mutation({
|
||||
|
||||
const ts = nowIso();
|
||||
await ctx.db.patch(existing._id, { deleted_at: null, deleted_by: null, updated_at: ts });
|
||||
return { ok: true };
|
||||
return {
|
||||
ok: true,
|
||||
workspace_id: existing.workspace_id,
|
||||
document_id: args.docId,
|
||||
mindmap_id: mindmapId,
|
||||
updated_at: ts,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -294,7 +345,12 @@ export const purge = mutation({
|
||||
}
|
||||
|
||||
await ctx.db.delete(existing._id);
|
||||
return { ok: true };
|
||||
return {
|
||||
ok: true,
|
||||
workspace_id: existing.workspace_id,
|
||||
document_id: args.docId,
|
||||
mindmap_id: mindmapId,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ export default defineSchema({
|
||||
|
||||
// 说明:当前文档内容结构还在演进,先用 any 承接(与 Supabase Json 一致的宽松形态)。
|
||||
content: v.any(),
|
||||
content_revision: v.optional(v.number()),
|
||||
content_conflict_key: v.optional(v.union(v.string(), v.null())),
|
||||
|
||||
// 说明:后续可用于搜索/索引(目前先留空,不强制写入)。
|
||||
raw_text: v.optional(v.union(v.string(), v.null())),
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
import { v } from "convex/values";
|
||||
import { query } from "./_generated/server";
|
||||
import { api } from "./_generated/api";
|
||||
import { requireUserId } from "./_utils/auth";
|
||||
|
||||
type MindmapRow = {
|
||||
mindmap_id: string;
|
||||
workspace_id?: string | null;
|
||||
document_id: string;
|
||||
data?: unknown;
|
||||
created_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
deleted_at?: string | null;
|
||||
deleted_by?: string | null;
|
||||
};
|
||||
|
||||
type TableRow = {
|
||||
id: string;
|
||||
workspace_id?: string | null;
|
||||
document_id: string;
|
||||
title?: string | null;
|
||||
created_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
deleted_at?: string | null;
|
||||
deleted_by?: string | null;
|
||||
purged_at?: string | null;
|
||||
is_archived?: boolean | null;
|
||||
};
|
||||
|
||||
function normalizeStringArray(values: Iterable<string>): string[] {
|
||||
return Array.from(new Set(values)).filter((value) => value.trim().length > 0);
|
||||
}
|
||||
|
||||
function extractMindmapImageAssetIdsFromData(input: unknown): string[] {
|
||||
const root = (() => {
|
||||
if (!input || typeof input !== "object") return input;
|
||||
const record = input as Record<string, unknown>;
|
||||
return record && typeof record === "object" && "root" in record ? record.root : input;
|
||||
})();
|
||||
|
||||
const ids: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
const push = (value: unknown) => {
|
||||
if (typeof value !== "string") return;
|
||||
if (!value.startsWith("asset:")) return;
|
||||
const id = value.slice("asset:".length).trim();
|
||||
if (!id || seen.has(id)) return;
|
||||
seen.add(id);
|
||||
ids.push(id);
|
||||
};
|
||||
|
||||
const get = (obj: unknown, key: string): unknown => {
|
||||
if (!obj || typeof obj !== "object") return undefined;
|
||||
return (obj as Record<string, unknown>)[key];
|
||||
};
|
||||
|
||||
const walk = (node: unknown) => {
|
||||
if (!node || typeof node !== "object") return;
|
||||
|
||||
const data = get(node, "data");
|
||||
const image = get(node, "image");
|
||||
|
||||
push(get(data, "image"));
|
||||
push(image);
|
||||
push(get(image, "url"));
|
||||
push(get(get(data, "image"), "url"));
|
||||
|
||||
const children = get(node, "children");
|
||||
if (Array.isArray(children)) {
|
||||
children.forEach(walk);
|
||||
}
|
||||
};
|
||||
|
||||
walk(root);
|
||||
return ids;
|
||||
}
|
||||
|
||||
function toMindmapAsset(row: MindmapRow, workspaceId: string) {
|
||||
const isLegacy = row.mindmap_id.startsWith("legacy-");
|
||||
return {
|
||||
id: row.mindmap_id,
|
||||
workspace_id: row.workspace_id ?? workspaceId,
|
||||
document_id: row.document_id,
|
||||
asset_type: "mindmap",
|
||||
file_url: null,
|
||||
thumbnail_url: null,
|
||||
bucket: null,
|
||||
storage_path: null,
|
||||
file_name: isLegacy ? "mindmap.json" : `mindmap-${row.mindmap_id}.json`,
|
||||
file_size: null,
|
||||
mime_type: "application/json",
|
||||
ocr_payload: undefined,
|
||||
ocr_strategy: null,
|
||||
ocr_text: null,
|
||||
ocr_status: null,
|
||||
signed_url: null,
|
||||
created_at: row.created_at ?? "",
|
||||
updated_at: row.updated_at ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
function toTrashedMindmapAsset(row: MindmapRow, workspaceId: string) {
|
||||
return {
|
||||
...toMindmapAsset(row, workspaceId),
|
||||
deleted_at: row.deleted_at ?? null,
|
||||
deleted_by: row.deleted_by ?? null,
|
||||
purged_at: null,
|
||||
};
|
||||
}
|
||||
|
||||
function toTableAsset(row: TableRow, workspaceId: string) {
|
||||
const base = String(row.title ?? "未命名表格").trim() || "未命名表格";
|
||||
const fileName = base.toLowerCase().endsWith(".luckysheet") ? base : `${base}.luckysheet`;
|
||||
return {
|
||||
id: row.id,
|
||||
workspace_id: row.workspace_id ?? workspaceId,
|
||||
document_id: row.document_id,
|
||||
asset_type: "luckysheet",
|
||||
file_url: null,
|
||||
thumbnail_url: null,
|
||||
bucket: null,
|
||||
storage_path: null,
|
||||
file_name: fileName,
|
||||
file_size: null,
|
||||
mime_type: "application/json",
|
||||
ocr_payload: undefined,
|
||||
ocr_strategy: null,
|
||||
ocr_text: null,
|
||||
ocr_status: null,
|
||||
signed_url: null,
|
||||
created_at: row.created_at ?? "",
|
||||
updated_at: row.updated_at ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
function toTrashedTableAsset(row: TableRow, workspaceId: string) {
|
||||
return {
|
||||
...toTableAsset(row, workspaceId),
|
||||
deleted_at: row.deleted_at ?? row.updated_at ?? null,
|
||||
deleted_by: row.deleted_by ?? null,
|
||||
purged_at: row.purged_at ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export const datasetList = query({
|
||||
args: {
|
||||
workspaceId: v.string(),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const userId = await requireUserId(ctx);
|
||||
|
||||
// 说明:这条查询作为 Sidebar 的单一数据集入口,先复用现有稳定 query,
|
||||
// 把前端原先“多 query + 多处拼装”收口成一条主查询契约。
|
||||
const [
|
||||
workspacesResult,
|
||||
documents,
|
||||
trashedDocuments,
|
||||
mindmaps,
|
||||
mediaAssets,
|
||||
trashedMediaAssets,
|
||||
tables,
|
||||
] = await Promise.all([
|
||||
ctx.runQuery(api.workspaces.fetchWorkspaceSummaries, {}),
|
||||
ctx.runQuery(api.documents.listByWorkspace, {
|
||||
workspaceId: args.workspaceId,
|
||||
}),
|
||||
ctx.runQuery(api.documents.listTrashedByWorkspace, {
|
||||
workspaceId: args.workspaceId,
|
||||
}),
|
||||
ctx.runQuery(api.mindmaps.listByWorkspace, {
|
||||
workspaceId: args.workspaceId,
|
||||
includeDeleted: true,
|
||||
}),
|
||||
ctx.runQuery(api.mediaAssets.listByWorkspace, {
|
||||
userId,
|
||||
workspaceId: args.workspaceId,
|
||||
limit: 200,
|
||||
}),
|
||||
ctx.runQuery(api.mediaAssets.listDeletedByWorkspace, {
|
||||
userId,
|
||||
workspaceId: args.workspaceId,
|
||||
limit: 2000,
|
||||
}),
|
||||
ctx.runQuery(api.tables.listByWorkspaceForSearch, {
|
||||
userId,
|
||||
workspaceId: args.workspaceId,
|
||||
includeArchived: true,
|
||||
limit: 3000,
|
||||
}),
|
||||
]);
|
||||
|
||||
const activeMindmaps = (mindmaps as MindmapRow[]).filter((row) => !row.deleted_at);
|
||||
const trashedMindmaps = (mindmaps as MindmapRow[]).filter((row) => Boolean(row.deleted_at));
|
||||
const activeTables = (tables as TableRow[]).filter((row) => !row.is_archived);
|
||||
const trashedTables = (tables as TableRow[]).filter((row) => Boolean(row.is_archived));
|
||||
|
||||
const mindmapAssetChildren: Record<string, string[]> = {};
|
||||
activeMindmaps.forEach((row) => {
|
||||
const ids = extractMindmapImageAssetIdsFromData(row.data);
|
||||
if (ids.length > 0) {
|
||||
mindmapAssetChildren[row.mindmap_id] = ids;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
active_workspace_id: args.workspaceId,
|
||||
workspaces: workspacesResult.workspaces,
|
||||
documents,
|
||||
trashed_documents: trashedDocuments,
|
||||
media_assets: mediaAssets ?? [],
|
||||
trashed_media_assets: trashedMediaAssets ?? [],
|
||||
mindmap_assets: activeMindmaps.map((row) => toMindmapAsset(row, args.workspaceId)),
|
||||
trashed_mindmap_assets: trashedMindmaps.map((row) =>
|
||||
toTrashedMindmapAsset(row, args.workspaceId),
|
||||
),
|
||||
table_assets: activeTables.map((row) => toTableAsset(row, args.workspaceId)),
|
||||
trashed_table_assets: trashedTables.map((row) => toTrashedTableAsset(row, args.workspaceId)),
|
||||
mindmap_docs: normalizeStringArray(activeMindmaps.map((row) => row.document_id)),
|
||||
mindmap_asset_children: mindmapAssetChildren,
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user