1
1
import path from 'node:path'
2
2
import { createQuestionByTitleSlug } from '../create-check/createUtil.js'
3
+ import { graphql } from '#common/utils/http/graphql.js'
3
4
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"}'
6
7
const headers = {
7
- 'content-type' : 'application/json' ,
8
+ 'content-type' : 'application/json'
8
9
}
9
10
10
11
const initJson = {
11
12
headers,
12
13
body : bodyString ,
13
- method : 'POST' ,
14
+ method : 'POST'
14
15
}
15
16
// 抓hot100列表
16
17
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 )
20
19
const {
21
- data : { studyPlanV2Detail } ,
20
+ data : { studyPlanV2Detail }
22
21
} = res
23
22
return studyPlanV2Detail
24
23
}
@@ -28,16 +27,16 @@ export async function getTitleSlugList() {
28
27
const res = await getHot100QuestionList ( )
29
28
const { planSubGroups } = res
30
29
return planSubGroups . reduce ( ( acc , cur ) => {
31
- acc . push ( ...cur . questions . map ( res => res . titleSlug ) )
30
+ acc . push ( ...cur . questions . map ( ( res ) => res . titleSlug ) )
32
31
return acc
33
32
} , [ ] )
34
33
}
35
34
// 获取创建promise列表
36
35
async function getPromiseList ( ) {
37
36
const titleSlugList = await getTitleSlugList ( )
38
37
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 )
41
40
)
42
41
}
43
42
0 commit comments