diff --git a/src/app/api/leetcode/route.ts b/src/app/api/leetcode/route.ts new file mode 100644 index 0000000000..86824aefb6 --- /dev/null +++ b/src/app/api/leetcode/route.ts @@ -0,0 +1,16 @@ +import type { NextRequest } from 'next/server' +import { NextResponse } from 'next/server' + +export const POST = async (req: NextRequest) => { + const requestBody = await req.json() + + const response = await fetch('https://leetcode.cn/graphql/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(requestBody), + }) + + return NextResponse.json(await response.json()) +} diff --git a/src/components/ui/link-card/LinkCard.tsx b/src/components/ui/link-card/LinkCard.tsx index 57b8495fe3..3958a53329 100644 --- a/src/components/ui/link-card/LinkCard.tsx +++ b/src/components/ui/link-card/LinkCard.tsx @@ -12,7 +12,6 @@ import uniqolor from 'uniqolor' import { LazyLoad } from '~/components/common/Lazyload' import { MingcuteStarHalfFill } from '~/components/icons/star' import { usePeek } from '~/components/modules/peek/usePeek' -import { API_URL } from '~/constants/env' import { LanguageToColorMap } from '~/constants/language' import { useIsClientTransition } from '~/hooks/common/use-is-client' import useIsCommandOrControlPressed from '~/hooks/common/use-is-command-or-control-pressed' @@ -526,7 +525,7 @@ const fetchLeetCodeQuestionData: FetchObject = { query: `query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {translatedTitle\n difficulty\n likes\n topicTags { translatedName\n }\n stats\n }\n}\n`, variables: { titleSlug: id }, } - const questionData = await fetch(`${API_URL}/fn/leetcode/shiro`, { + const questionData = await fetch(`/api/leetcode`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -588,38 +587,31 @@ const fetchLeetCodeQuestionData: FetchObject = { console.error('Error fetching LeetCode question data:', err) throw err } - }, -} - -// 映射难度到颜色的函数 -function getDifficultyColor(difficulty: string) { - switch (difficulty) { - case 'Easy': - return '#00BFA5' - case 'Medium': - return '#FFA726' - case 'Hard': - return '#F44336' - default: - return '#757575' - } -} -// 难度字体颜色className -function getDifficultyColorClass(difficulty: string) { - switch (difficulty) { - case 'Easy': - return 'text-green-500' - case 'Medium': - return 'text-yellow-500' - case 'Hard': - return 'text-red-500' - default: - return 'text-gray-500' - } -} + function getDifficultyColor(difficulty: string) { + switch (difficulty) { + case 'Easy': + return '#00BFA5' + case 'Medium': + return '#FFA726' + case 'Hard': + return '#F44336' + default: + return '#757575' + } + } -interface LeetCodeResponse { - query: string - variables: Record + function getDifficultyColorClass(difficulty: string) { + switch (difficulty) { + case 'Easy': + return 'text-green-500' + case 'Medium': + return 'text-yellow-500' + case 'Hard': + return 'text-red-500' + default: + return 'text-gray-500' + } + } + }, }