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
+5 -20
View File
@@ -2,6 +2,7 @@ import { mutation, query } from "./_generated/server";
import { v } from "convex/values";
import { getAuthUserId } from "@convex-dev/auth/server";
import { nowIso } from "./_utils/time";
import { getCanonicalDocumentByBusinessId, getCanonicalParentDocumentId } from "./_utils/documentRecord";
type SharePermission = "read" | "edit";
@@ -34,12 +35,7 @@ async function resolveSharePermission(ctx: any, doc: any, userId: string): Promi
.withIndex("by_doc_user", (q: any) => q.eq("document_id", parentId).eq("shared_with_user_id", userId))
.first();
if (parentShare && parentShare.include_descendants) return parentShare.permission as SharePermission;
const parent = await ctx.db
.query("documents")
.withIndex("by_document_id", (q: any) => q.eq("id", parentId))
.first();
parentId = parent?.parent_id ?? null;
parentId = await getCanonicalParentDocumentId(ctx, parentId);
}
return null;
}
@@ -89,12 +85,7 @@ async function resolveGroupSharePermission(ctx: any, doc: any, userId: string):
let parentId: string | null = doc.parent_id ?? null;
for (let depth = 0; depth < 60 && parentId; depth += 1) {
if (await checkDocId(parentId, true)) return "edit";
const parent = await ctx.db
.query("documents")
.withIndex("by_document_id", (q: any) => q.eq("id", parentId))
.first();
parentId = parent?.parent_id ?? null;
parentId = await getCanonicalParentDocumentId(ctx, parentId);
}
return best;
@@ -109,10 +100,7 @@ export const isStarred = query({
if (authUserId === null) return false;
const userId = String(authUserId);
const doc = await ctx.db
.query("documents")
.withIndex("by_document_id", (q: any) => q.eq("id", args.documentId))
.first();
const doc = await getCanonicalDocumentByBusinessId<any>(ctx, args.documentId);
if (!doc) return false;
if (doc.deleted_at != null) return false;
@@ -137,10 +125,7 @@ export const toggle = mutation({
handler: async (ctx, args) => {
const userId = await requireUserId(ctx);
const doc = await ctx.db
.query("documents")
.withIndex("by_document_id", (q: any) => q.eq("id", args.documentId))
.first();
const doc = await getCanonicalDocumentByBusinessId<any>(ctx, args.documentId);
if (!doc) throw new Error("页面不存在");
if (doc.deleted_at != null) throw new Error("页面不存在");