This commit is contained in:
asabizanjo
2025-12-11 01:05:24 +00:00
parent c713d58f98
commit 423ce1bc6d
88 changed files with 4081 additions and 122 deletions

View File

@@ -0,0 +1,33 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { getSessionUser } from "@/lib/auth";
import { deleteFromR2 } from "@/lib/r2";
export async function DELETE() {
const session = await getSessionUser();
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
// Get all files for the user
const files = await prisma.file.findMany({
where: { userId: session.userId },
select: { id: true, key: true },
});
if (files.length === 0) {
return NextResponse.json({ ok: true, deleted: 0 });
}
// Delete all files from R2
const deletePromises = files.map((file) => deleteFromR2(file.key));
await Promise.all(deletePromises);
// Delete all file records from database
await prisma.file.deleteMany({
where: { userId: session.userId },
});
return NextResponse.json({ ok: true, deleted: files.length });
}