Skip to content

Commit

Permalink
feat: new API
Browse files Browse the repository at this point in the history
  • Loading branch information
fluid-design-io committed Oct 18, 2023
1 parent ed48cbf commit 8728c8b
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions apps/web/app/api/generate-color-palette/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { generateColorPalette } from "@/lib/colorCalculator";
import { colorHelper } from "@/lib/colorHelper";
import { BaseColorTypes, ColorMode } from "@/types/app";
import { NextResponse } from "next/server";

export async function GET(req: Request) {
const origin = req.headers.get("origin");
const { searchParams } = new URL(req.url);
const colorsString = searchParams.get("colors");
console.log({ colorsString });
if (!colorsString) {
return NextResponse.json(
{
data: null,
error: {
message: "Invalid token",
},
},
{
status: 400,
},
);
}
const baseColors = colorHelper.colorStringToBaseColors(colorsString);
const mode = ColorMode.HEX;
const [primaryPalette, secondaryPalette, accentPalette, grayPalette] = [
"primary",
"secondary",
"accent",
"gray",
].map((color) =>
generateColorPalette({
color: color === "gray" ? baseColors.primary : baseColors[color],
type: color as BaseColorTypes,
colorMode: mode,
}),
);
return NextResponse.json(
{
data: {
baseColors,
colorPalettes: {
primary: primaryPalette,
secondary: secondaryPalette,
accent: accentPalette,
gray: grayPalette,
},
colorMode: mode,
},
error: null,
},
{
status: 200,
},
);
}

0 comments on commit 8728c8b

Please sign in to comment.