Files
mnote/wolai-frontend/src/app/api/documents/restore/route.ts
T

55 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-11-23 10:55:04 +08:00
import { NextResponse } from "next/server";
2026-01-17 10:12:53 +08:00
import { isConvexEnabled } from "@/lib/convex/enabled";
2026-01-18 19:01:31 +08:00
import { getAuthedConvexClient } from "@/lib/convex/route";
2026-01-17 10:12:53 +08:00
import { api } from "@/lib/convex/api";
2025-11-23 10:55:04 +08:00
export const dynamic = "force-dynamic";
export async function POST(request: Request) {
2026-01-17 10:12:53 +08:00
if (isConvexEnabled()) {
const { documentId } = await request.json();
if (!documentId) {
return NextResponse.json({ error: "缺少 documentId" }, { status: 400 });
}
2026-01-18 19:01:31 +08:00
const { client } = await getAuthedConvexClient();
await client.mutation(api.documents.restore, { id: documentId });
2026-01-17 10:12:53 +08:00
return NextResponse.json({ success: true });
}
2026-01-18 19:01:31 +08:00
return NextResponse.json({ error: "当前仅支持 Convex 模式" }, { status: 501 });
/*
2025-11-23 10:55:04 +08:00
const supabase = await createSupabaseRouteClient();
const {
data: { session },
} = await supabase.auth.getSession();
if (!session) {
return NextResponse.json({ error: "未登录" }, { status: 401 });
}
const { documentId } = await request.json();
if (!documentId) {
return NextResponse.json({ error: "缺少 documentId" }, { status: 400 });
}
const { error } = await supabase
.from("documents")
.update({
deleted_at: null,
deleted_by: null,
parent_id: null,
access_scope: "private",
})
.eq("id", documentId)
.eq("user_id", session.user.id);
if (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
return NextResponse.json({ success: true });
2026-01-18 19:01:31 +08:00
*/
2025-11-23 10:55:04 +08:00
}