-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed48cbf
commit 8728c8b
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
); | ||
} |