39 lines
981 B
TypeScript
39 lines
981 B
TypeScript
|
|
import { NextRequest, NextResponse } from "next/server";
|
||
|
|
import { ScrapydClient } from "@/lib/scrapyd-client";
|
||
|
|
|
||
|
|
export async function GET() {
|
||
|
|
try {
|
||
|
|
const data = await ScrapydClient.listProjects();
|
||
|
|
return NextResponse.json(data);
|
||
|
|
} catch (error) {
|
||
|
|
console.error("Failed to fetch projects:", error);
|
||
|
|
return NextResponse.json(
|
||
|
|
{ error: "Failed to fetch projects" },
|
||
|
|
{ status: 500 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function DELETE(request: NextRequest) {
|
||
|
|
try {
|
||
|
|
const body = await request.json();
|
||
|
|
const { project } = body;
|
||
|
|
|
||
|
|
if (!project) {
|
||
|
|
return NextResponse.json(
|
||
|
|
{ error: "Project name is required" },
|
||
|
|
{ status: 400 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
const data = await ScrapydClient.deleteProject({ project });
|
||
|
|
return NextResponse.json(data);
|
||
|
|
} catch (error) {
|
||
|
|
console.error("Failed to delete project:", error);
|
||
|
|
return NextResponse.json(
|
||
|
|
{ error: "Failed to delete project" },
|
||
|
|
{ status: 500 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|