mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-11 09:51:40 +00:00
* feat: chart color * fix * fix * fix: chart color * chore: changeset * chore: restore directory registry formatting * feat: add fontHeading * feat: rebuild registry * fix: v0 * refactor * fix * fix * fix * fix * fix * fix: refactor preset handling * fix * fix * fix
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { NextResponse, type NextRequest } from "next/server"
|
|
import { track } from "@vercel/analytics/server"
|
|
import { isPresetCode } from "shadcn/preset"
|
|
import { registryItemSchema } from "shadcn/schema"
|
|
|
|
import { buildRegistryBase } from "@/registry/config"
|
|
import { parseDesignSystemConfig } from "@/app/(create)/init/parse-config"
|
|
import { getPresetCode } from "@/app/(create)/lib/preset-code"
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const searchParams = request.nextUrl.searchParams
|
|
const result = parseDesignSystemConfig(searchParams)
|
|
|
|
if (!result.success) {
|
|
return NextResponse.json({ error: result.error }, { status: 400 })
|
|
}
|
|
|
|
const rawPreset = searchParams.get("preset")
|
|
const presetCode =
|
|
rawPreset && isPresetCode(rawPreset)
|
|
? rawPreset
|
|
: getPresetCode(result.data)
|
|
|
|
const registryBase = buildRegistryBase(result.data)
|
|
const parseResult = registryItemSchema.safeParse(registryBase)
|
|
|
|
if (!parseResult.success) {
|
|
return NextResponse.json(
|
|
{
|
|
error: "Invalid registry base item",
|
|
details: parseResult.error.format(),
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
|
|
if (searchParams.get("track") === "1") {
|
|
track("create_app", {
|
|
...result.data,
|
|
preset: presetCode,
|
|
})
|
|
}
|
|
|
|
return NextResponse.json(parseResult.data)
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{
|
|
error:
|
|
error instanceof Error ? error.message : "An unknown error occurred",
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|