Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
parkpow
GitHub Repository: parkpow/deep-license-plate-recognition
Path: blob/master/webhooks/webhook_preview/app/api/new-webhook/route.ts
640 views
1
import { prisma } from "@/lib/prisma";
2
import { NextResponse } from "next/server";
3
import type { NextRequest } from "next/server";
4
5
export async function POST(request: NextRequest) {
6
try {
7
const body = await request.json();
8
const { uuid } = body;
9
10
const uuidRegex =
11
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
12
13
if (!uuid || !uuidRegex.test(uuid)) {
14
return NextResponse.json(
15
{ success: false, message: "Invalid UUID" },
16
{ status: 400 },
17
);
18
}
19
20
let webhook = await prisma.webhook.findUnique({
21
where: { uuid },
22
});
23
24
if (!webhook) {
25
webhook = await prisma.webhook.create({
26
data: { uuid },
27
});
28
}
29
30
return NextResponse.json(
31
{ success: true, message: "Webhook created" },
32
{ status: 201 },
33
);
34
} catch (error) {
35
console.error("Webhook creation error:", error);
36
return NextResponse.json(
37
{ success: false, message: "Internal Server Error" },
38
{ status: 500 },
39
);
40
}
41
}
42
43