33 lines
801 B
TypeScript
33 lines
801 B
TypeScript
import { NextResponse } from "next/server";
|
|||
|
|
import { createSupabaseRouteClient } from "@/lib/supabase/server";
|
||
|
|
|
||
|
|
interface RenamePayload {
|
||
|
|
documentId: string;
|
||
|
|
title: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function POST(request: Request) {
|
||
|
|
const supabase = await createSupabaseRouteClient();
|
||
|
|
const {
|
||
|
|
data: { session },
|
||
|
|
} = await supabase.auth.getSession();
|
||
|
|
|
||
|
|
if (!session) {
|
||
|
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
||
|
|
}
|
||
|
|
|
||
|
|
const { documentId, title }: RenamePayload = await request.json();
|
||
|
|
|
||
|
|
const { error } = await supabase
|
||
|
|
.from("documents")
|
||
|
|
.update({ title })
|
||
|
|
.eq("id", documentId)
|
||
|
|
.eq("user_id", session.user.id);
|
||
|
|
|
||
|
|
if (error) {
|
||
|
|
return NextResponse.json({ error: error.message }, { status: 400 });
|
||
|
|
}
|
||
|
|
|
||
|
|
return NextResponse.json({ ok: true });
|
||
|
|
}
|