From f4bcc2b55e6248334810cddb31b103630ae332f2 Mon Sep 17 00:00:00 2001 From: Oliver Pan <2216991777@qq.com> Date: Mon, 24 Jun 2024 00:22:15 -0500 Subject: [PATCH] chore: lint --- .../generate-color-palette/route.ts | 89 +++++++++---------- .../v1/figma-plugin/notifications/route.ts | 8 +- apps/web/app/api/v1/figma-plugin/route.ts | 20 ++--- 3 files changed, 56 insertions(+), 61 deletions(-) diff --git a/apps/web/app/api/v1/figma-plugin/generate-color-palette/route.ts b/apps/web/app/api/v1/figma-plugin/generate-color-palette/route.ts index 50c1a7d..735cffc 100644 --- a/apps/web/app/api/v1/figma-plugin/generate-color-palette/route.ts +++ b/apps/web/app/api/v1/figma-plugin/generate-color-palette/route.ts @@ -1,95 +1,90 @@ -import { NextResponse } from "next/server"; -import jwt from "jsonwebtoken"; -import { BaseColorTypes, BaseColors, ColorMode, RawColor } from "@/types/app"; -import { generateColorPalette } from "@/lib/colorCalculator"; +import { generateColorPalette } from '@/lib/colorCalculator' +import { BaseColorTypes, BaseColors, ColorMode } from '@/types/app' +import jwt from 'jsonwebtoken' +import { NextResponse } from 'next/server' const headers = (origin: string) => ({ - "Access-Control-Allow-Origin": origin || "*", - "Access-Control-Allow-Methods": "GET, POST, OPTIONS", - "Access-Control-Allow-Credentials": "true", - "Access-Control-Allow-Headers": "Content-Type, Authorization, Accept", -}); + 'Access-Control-Allow-Credentials': 'true', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, Accept', + 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', + 'Access-Control-Allow-Origin': origin || '*', +}) export async function OPTIONS(request: Request) { - const origin = request.headers.get("origin"); + const origin = request.headers.get('origin') return new Response(null, { - status: 200, headers: headers(origin), - }); + status: 200, + }) } export async function GET(req: Request) { - const origin = req.headers.get("origin"); + const origin = req.headers.get('origin') - const { searchParams } = new URL(req.url); - const token = searchParams.get("token"); - const authSecret = process.env.FIGMA_AUTH_SECRET; + const { searchParams } = new URL(req.url) + const token = searchParams.get('token') + const authSecret = process.env.FIGMA_AUTH_SECRET // decode the token using the same secret key // we should get the base colors - let baseColors: Partial; + let baseColors: Partial try { - baseColors = jwt.verify(token, authSecret); + baseColors = jwt.verify(token, authSecret) } catch (error) { - console.log(`====> Error:`, error); + console.log(`====> Error:`, error) return NextResponse.json( { data: null, error: { - message: "Invalid token", + message: 'Invalid token', }, }, { - status: 400, headers: headers(origin), - }, - ); + status: 400, + } + ) } - const { primary, secondary, accent } = baseColors as BaseColors; + const { accent, primary, secondary } = baseColors as BaseColors if (!primary || !secondary || !accent) { return NextResponse.json( { data: null, error: { - message: "Missing primary, secondary or accent color", + message: 'Missing primary, secondary or accent color', }, }, { - status: 400, headers: headers(origin), - }, - ); + status: 400, + } + ) } // !TODO: get mode from query params - 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, - }), - ); + 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, + }) + ) return NextResponse.json( { - error: null, data: { baseColors, + colorMode: mode, colorPalettes: { - primary: primaryPalette, - secondary: secondaryPalette, accent: accentPalette, gray: grayPalette, + primary: primaryPalette, + secondary: secondaryPalette, }, - colorMode: mode, }, + error: null, }, { headers: headers(origin), - }, - ); + } + ) } diff --git a/apps/web/app/api/v1/figma-plugin/notifications/route.ts b/apps/web/app/api/v1/figma-plugin/notifications/route.ts index a5de8f1..5c4d656 100644 --- a/apps/web/app/api/v1/figma-plugin/notifications/route.ts +++ b/apps/web/app/api/v1/figma-plugin/notifications/route.ts @@ -1,25 +1,25 @@ import { NextResponse } from "next/server"; const headers = (origin: string) => ({ - "Access-Control-Allow-Origin": origin || "*", - "Access-Control-Allow-Methods": "GET, POST, OPTIONS", "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Headers": "Content-Type, Authorization, Accept", + "Access-Control-Allow-Methods": "GET, POST, OPTIONS", + "Access-Control-Allow-Origin": origin || "*", }); export async function OPTIONS(request: Request) { const origin = request.headers.get("origin"); return new Response(null, { - status: 200, headers: headers(origin), + status: 200, }); } type NotificationType = "error" | "info" | "none"; type Notification = { - message: string; href?: string; + message: string; type: NotificationType; }; diff --git a/apps/web/app/api/v1/figma-plugin/route.ts b/apps/web/app/api/v1/figma-plugin/route.ts index 5752086..c2d715d 100644 --- a/apps/web/app/api/v1/figma-plugin/route.ts +++ b/apps/web/app/api/v1/figma-plugin/route.ts @@ -1,21 +1,21 @@ -import { NextResponse } from "next/server"; -import tinycolor from "tinycolor2"; import { BaseColors, RawColor } from "@/types/app"; import jwt from "jsonwebtoken"; +import { NextResponse } from "next/server"; +import tinycolor from "tinycolor2"; const headers = (origin: string) => ({ - "Access-Control-Allow-Origin": origin || "*", - "Access-Control-Allow-Methods": "GET, POST, OPTIONS", "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Headers": "Content-Type, Authorization, Accept", + "Access-Control-Allow-Methods": "GET, POST, OPTIONS", + "Access-Control-Allow-Origin": origin || "*", }); export async function OPTIONS(request: Request) { const origin = request.headers.get("origin"); return new Response(null, { - status: 200, headers: headers(origin), + status: 200, }); } export async function POST(request: Request) { @@ -66,13 +66,13 @@ export async function GET(req: Request) { }, }, { - status: 400, headers: headers(origin), + status: 400, }, ); } - const { primary, secondary, accent } = baseColors as BaseColors; - const v = (color: string | RawColor) => tinycolor(color).isValid(); + const { accent, primary, secondary } = baseColors as BaseColors; + const v = (color: RawColor | string) => tinycolor(color).isValid(); if (!v(primary) || !v(secondary) || !v(accent)) { return NextResponse.json( { @@ -82,17 +82,17 @@ export async function GET(req: Request) { }, }, { - status: 400, headers: headers(origin), + status: 400, }, ); } return NextResponse.json( { data: { + accent, primary, secondary, - accent, }, error: null, },