This commit is contained in:
Vaica committed 2026-06-22 13:20:07 +08:00
1 parent e36c99476a
commit f172e6c15b
3 files changed
+177 -1

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
import { NextRequest, NextResponse } from "next/server";
import {
listRecycle,
restoreFromRecycle,
permanentDelete,
} from "@/lib/recycle";
export async function GET() {
try {
const items = listRecycle();
return NextResponse.json({ items });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { slug } = body;
if (!slug) {
return NextResponse.json({ error: "Slug is required" }, { status: 400 });
}
const success = restoreFromRecycle(slug);
if (!success) {
return NextResponse.json(
{ error: "Item not found in recycle bin" },
{ status: 404 }
);
}
return NextResponse.json({ success: true });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}
export async function DELETE(request: NextRequest) {
try {
const { searchParams } = request.nextUrl;
const slug = searchParams.get("slug");
if (!slug) {
return NextResponse.json({ error: "Slug is required" }, { status: 400 });
}
const success = permanentDelete(slug);
if (!success) {
return NextResponse.json(
{ error: "Item not found in recycle bin" },
{ status: 404 }
);
}
return NextResponse.json({ success: true });
} catch (error: unknown) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Unknown error" },
{ status: 500 }
);
}
}