0.6 rust重构01
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { internalMutation, internalQuery, mutation, query } from "./_generated/server";
|
||||
import { v } from "convex/values";
|
||||
import { getAuthUserId } from "@convex-dev/auth/server";
|
||||
import { requireUserId } from "./_utils/auth";
|
||||
import { nowIso } from "./_utils/time";
|
||||
import { enqueueIngestMindmapJob } from "./_utils/ingestJobs";
|
||||
import { internal } from "./_generated/api";
|
||||
import { requireCanonicalOwnedDocument } from "./_utils/documentRecord";
|
||||
|
||||
const defaultMindmapData = {
|
||||
data: { text: "中心主题" },
|
||||
@@ -19,14 +20,6 @@ function resolveGraceSeconds(): number {
|
||||
return Math.floor(parsed);
|
||||
}
|
||||
|
||||
async function requireUserId(ctx: any): Promise<string> {
|
||||
const userId = await getAuthUserId(ctx);
|
||||
if (userId === null) {
|
||||
throw new Error("未登录");
|
||||
}
|
||||
return userId;
|
||||
}
|
||||
|
||||
function normalizeMindmapId(docId: string, mindmapId: string): string {
|
||||
const raw = String(mindmapId ?? "").trim();
|
||||
if (raw) return raw;
|
||||
@@ -35,17 +28,7 @@ function normalizeMindmapId(docId: string, mindmapId: string): string {
|
||||
}
|
||||
|
||||
async function requireOwnedDocument(ctx: any, userId: string, docId: string) {
|
||||
const doc = await ctx.db
|
||||
.query("documents")
|
||||
.withIndex("by_document_id", (q: any) => q.eq("id", docId))
|
||||
.first();
|
||||
if (!doc) {
|
||||
throw new Error("页面不存在");
|
||||
}
|
||||
if (doc.user_id !== userId) {
|
||||
throw new Error("无权限");
|
||||
}
|
||||
return doc;
|
||||
return await requireCanonicalOwnedDocument<any>(ctx, docId, userId);
|
||||
}
|
||||
|
||||
export const get = query({
|
||||
|
||||
Reference in New Issue
Block a user