Skip to content

Commit 0649f97

Browse files
committed
fix: leetcode api proxy
Signed-off-by: Innei <[email protected]>
1 parent 7df7448 commit 0649f97

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

src/app/api/leetcode/route.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { NextRequest } from 'next/server'
2+
import { NextResponse } from 'next/server'
3+
4+
export const POST = async (req: NextRequest) => {
5+
const requestBody = await req.json()
6+
7+
const response = await fetch('https://leetcode.cn/graphql/', {
8+
method: 'POST',
9+
headers: {
10+
'Content-Type': 'application/json',
11+
},
12+
body: JSON.stringify(requestBody),
13+
})
14+
15+
return NextResponse.json(await response.json())
16+
}

src/components/ui/link-card/LinkCard.tsx

+26-34
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import uniqolor from 'uniqolor'
1212
import { LazyLoad } from '~/components/common/Lazyload'
1313
import { MingcuteStarHalfFill } from '~/components/icons/star'
1414
import { usePeek } from '~/components/modules/peek/usePeek'
15-
import { API_URL } from '~/constants/env'
1615
import { LanguageToColorMap } from '~/constants/language'
1716
import { useIsClientTransition } from '~/hooks/common/use-is-client'
1817
import useIsCommandOrControlPressed from '~/hooks/common/use-is-command-or-control-pressed'
@@ -526,7 +525,7 @@ const fetchLeetCodeQuestionData: FetchObject = {
526525
query: `query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {translatedTitle\n difficulty\n likes\n topicTags { translatedName\n }\n stats\n }\n}\n`,
527526
variables: { titleSlug: id },
528527
}
529-
const questionData = await fetch(`${API_URL}/fn/leetcode/shiro`, {
528+
const questionData = await fetch(`/api/leetcode`, {
530529
method: 'POST',
531530
headers: {
532531
'Content-Type': 'application/json',
@@ -588,38 +587,31 @@ const fetchLeetCodeQuestionData: FetchObject = {
588587
console.error('Error fetching LeetCode question data:', err)
589588
throw err
590589
}
591-
},
592-
}
593-
594-
// 映射难度到颜色的函数
595-
function getDifficultyColor(difficulty: string) {
596-
switch (difficulty) {
597-
case 'Easy':
598-
return '#00BFA5'
599-
case 'Medium':
600-
return '#FFA726'
601-
case 'Hard':
602-
return '#F44336'
603-
default:
604-
return '#757575'
605-
}
606-
}
607590

608-
// 难度字体颜色className
609-
function getDifficultyColorClass(difficulty: string) {
610-
switch (difficulty) {
611-
case 'Easy':
612-
return 'text-green-500'
613-
case 'Medium':
614-
return 'text-yellow-500'
615-
case 'Hard':
616-
return 'text-red-500'
617-
default:
618-
return 'text-gray-500'
619-
}
620-
}
591+
function getDifficultyColor(difficulty: string) {
592+
switch (difficulty) {
593+
case 'Easy':
594+
return '#00BFA5'
595+
case 'Medium':
596+
return '#FFA726'
597+
case 'Hard':
598+
return '#F44336'
599+
default:
600+
return '#757575'
601+
}
602+
}
621603

622-
interface LeetCodeResponse {
623-
query: string
624-
variables: Record<string, any>
604+
function getDifficultyColorClass(difficulty: string) {
605+
switch (difficulty) {
606+
case 'Easy':
607+
return 'text-green-500'
608+
case 'Medium':
609+
return 'text-yellow-500'
610+
case 'Hard':
611+
return 'text-red-500'
612+
default:
613+
return 'text-gray-500'
614+
}
615+
}
616+
},
625617
}

0 commit comments

Comments
 (0)