0.2.1 onlyoffice修复

This commit is contained in:
liaibo
2026-01-17 10:12:53 +08:00
parent 94957dc361
commit 19907bccdc
102 changed files with 7188 additions and 186 deletions
@@ -3,6 +3,9 @@ import { createSupabaseRouteClient } from "@/lib/supabase/server";
import { promises as fs } from "fs";
import path from "path";
import { getDocumentsBaseDir, getLegacyMindmapsBaseDir } from "@/lib/server/local-paths";
import { isConvexEnabled } from "@/lib/convex/enabled";
import { getAuthedConvexClient } from "@/lib/convex/route";
import { api } from "@/lib/convex/api";
const defaultMindmapData = {
data: { text: "中心主题" },
@@ -112,6 +115,17 @@ export async function GET(
{ params }: { params: Promise<{ docId: string; mindmapId: string }> },
) {
const { docId, mindmapId } = await params;
if (isConvexEnabled()) {
const { auth, client } = getAuthedConvexClient();
const res = await client.query(api.mindmaps.get, {
userId: auth.userId,
docId,
mindmapId,
});
return NextResponse.json({ data: res?.data ?? defaultMindmapData, source: "convex" });
}
const supabase = await createSupabaseRouteClient();
const {
data: { session },
@@ -155,6 +169,28 @@ export async function POST(
{ params }: { params: Promise<{ docId: string; mindmapId: string }> },
) {
const { docId, mindmapId } = await params;
if (isConvexEnabled()) {
const { auth, client } = getAuthedConvexClient();
const { data, createOnly } = (await request.json().catch(() => ({ data: null }))) as {
data?: unknown;
createOnly?: boolean;
};
try {
const result = await client.mutation(api.mindmaps.put, {
userId: auth.userId,
docId,
mindmapId,
data: data ?? defaultMindmapData,
...(typeof createOnly === "boolean" ? { createOnly } : {}),
});
return NextResponse.json({ ok: true, ...(result ?? {}) });
} catch (error) {
return NextResponse.json({ error: (error as Error).message }, { status: 400 });
}
}
const supabase = await createSupabaseRouteClient();
const {
data: { session },
@@ -203,6 +239,21 @@ export async function DELETE(
{ params }: { params: Promise<{ docId: string; mindmapId: string }> },
) {
const { docId, mindmapId } = await params;
if (isConvexEnabled()) {
const { auth, client } = getAuthedConvexClient();
try {
const result = await client.mutation(api.mindmaps.softDelete, {
userId: auth.userId,
docId,
mindmapId,
});
return NextResponse.json({ ok: true, ...(result ?? {}) });
} catch (error) {
return NextResponse.json({ error: (error as Error).message }, { status: 400 });
}
}
const supabase = await createSupabaseRouteClient();
const {
data: { session },
@@ -263,6 +314,37 @@ export async function PATCH(
{ params }: { params: Promise<{ docId: string; mindmapId: string }> },
) {
const { docId, mindmapId } = await params;
if (isConvexEnabled()) {
const { auth, client } = getAuthedConvexClient();
const { action } = (await request.json().catch(() => ({}))) as { action?: string };
if (action !== "restore" && action !== "purge") {
return NextResponse.json({ error: "不支持的操作" }, { status: 400 });
}
try {
if (action === "purge") {
const result = await client.mutation(api.mindmaps.purge, {
userId: auth.userId,
docId,
mindmapId,
});
return NextResponse.json({ ok: true, ...(result ?? {}) });
}
const result = await client.mutation(api.mindmaps.restore, {
userId: auth.userId,
docId,
mindmapId,
});
return NextResponse.json({ ok: true, ...(result ?? {}) });
} catch (error) {
const msg = (error as Error).message ?? "操作失败";
const status = msg.includes("未找到") ? 404 : 400;
return NextResponse.json({ error: msg }, { status });
}
}
const supabase = await createSupabaseRouteClient();
const {
data: { session },