Skip to content

Commit e738add

Browse files
committed
fix:all fetch use fetch_ impletment
1 parent 1c91856 commit e738add

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

common/utils/http/fetch_.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* @private
77
*/
88
export async function fetch_(url, options) {
9-
return await fetch(url, options).then(res => res.json())
9+
return await fetch(url, options).then((res) => res.json())
1010
}

common/utils/question-handler/getHot100QuestionList.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import path from 'node:path'
22
import { createQuestionByTitleSlug } from '../create-check/createUtil.js'
3+
import { graphql } from '#common/utils/http/graphql.js'
34

4-
const bodyString
5-
= '{"query":"\\n query studyPlanPastSolved($slug: String!) {\\n studyPlanV2Detail(planSlug: $slug) {\\n planSubGroups {\\n slug\\n questions {\\n titleSlug\\n status\\n }\\n }\\n }\\n}\\n ","variables":{"slug":"top-100-liked"},"operationName":"studyPlanPastSolved"}'
5+
const bodyString =
6+
'{"query":"\\n query studyPlanPastSolved($slug: String!) {\\n studyPlanV2Detail(planSlug: $slug) {\\n planSubGroups {\\n slug\\n questions {\\n titleSlug\\n status\\n }\\n }\\n }\\n}\\n ","variables":{"slug":"top-100-liked"},"operationName":"studyPlanPastSolved"}'
67
const headers = {
7-
'content-type': 'application/json',
8+
'content-type': 'application/json'
89
}
910

1011
const initJson = {
1112
headers,
1213
body: bodyString,
13-
method: 'POST',
14+
method: 'POST'
1415
}
1516
// 抓hot100列表
1617
export async function getHot100QuestionList() {
17-
const res = await fetch('https://leetcode.cn/graphql/', initJson).then(
18-
res => res.json(),
19-
)
18+
const res = await graphql(initJson)
2019
const {
21-
data: { studyPlanV2Detail },
20+
data: { studyPlanV2Detail }
2221
} = res
2322
return studyPlanV2Detail
2423
}
@@ -28,16 +27,16 @@ export async function getTitleSlugList() {
2827
const res = await getHot100QuestionList()
2928
const { planSubGroups } = res
3029
return planSubGroups.reduce((acc, cur) => {
31-
acc.push(...cur.questions.map(res => res.titleSlug))
30+
acc.push(...cur.questions.map((res) => res.titleSlug))
3231
return acc
3332
}, [])
3433
}
3534
// 获取创建promise列表
3635
async function getPromiseList() {
3736
const titleSlugList = await getTitleSlugList()
3837
const dir = path.join(process.cwd(), 'hot100')
39-
return titleSlugList.map(titleSlug =>
40-
createQuestionByTitleSlug(titleSlug, dir),
38+
return titleSlugList.map((titleSlug) =>
39+
createQuestionByTitleSlug(titleSlug, dir)
4140
)
4241
}
4342

common/utils/question-handler/getQuestionIdBySlug.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1+
import { graphql } from '#common/utils/http/graphql.js'
2+
13
const headers = {
2-
'content-type': 'application/json',
4+
'content-type': 'application/json'
35
}
46

57
export async function getQuestionIdBySlug(titleSlug) {
68
const body = {
79
query:
810
'\n query questionTitle($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n title\n titleSlug\n isPaidOnly\n difficulty\n likes\n dislikes\n categoryTitle\n }\n}\n ',
911
variables: {
10-
titleSlug,
12+
titleSlug
1113
},
12-
operationName: 'questionTitle',
14+
operationName: 'questionTitle'
1315
}
1416
const initJson = {
1517
headers,
1618
body: JSON.stringify(body),
17-
method: 'POST',
19+
method: 'POST'
1820
}
19-
const res = await fetch('https://leetcode.cn/graphql/', initJson).then(
20-
res => res.json(),
21-
)
21+
const res = await graphql(initJson)
2222
const { data: question } = res
2323
return question
2424
}

0 commit comments

Comments
 (0)