import { NextResponse } from "next/server"; import { prisma } from "@/lib/db"; import { getSessionUser } from "@/lib/auth"; import { deleteFromR2 } from "@/lib/r2"; type Props = { params: Promise<{ id: string }>; }; export async function DELETE(_req: Request, { params }: Props) { const session = await getSessionUser(); if (!session) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const { id } = await params; const file = await prisma.file.findFirst({ where: { id, userId: session.userId }, }); if (!file) { return NextResponse.json({ error: "File not found" }, { status: 404 }); } await deleteFromR2(file.key); await prisma.file.delete({ where: { id: file.id } }); return NextResponse.json({ ok: true }); }