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 } ); } }