-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit-in-v0.ts
50 lines (43 loc) · 1.06 KB
/
edit-in-v0.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use server"
import { track } from "@vercel/analytics/server"
const EDIT_IN_V0_SOURCE = "ui.shadcn.com"
export async function editInV0({
name,
description,
style,
code,
}: {
name: string
description: string
style: string
code: string
}) {
try {
await track("edit_in_v0", {
name,
description,
style,
})
const response = await fetch(`${process.env.V0_URL}/api/edit`, {
method: "POST",
body: JSON.stringify({ description, code, source: EDIT_IN_V0_SOURCE }),
headers: {
"x-v0-edit-secret": process.env.V0_EDIT_SECRET!,
"x-vercel-protection-bypass":
process.env.DEPLOYMENT_PROTECTION_BYPASS || "not-set",
"Content-Type": "application/json",
},
})
if (!response.ok) {
if (response.status === 403) {
throw new Error("Unauthorized")
}
throw new Error("Something went wrong. Please try again later.")
}
return await response.json()
} catch (error) {
if (error instanceof Error) {
return { error: error.message }
}
}
}