Skip to content

Commit 9d7a22f

Browse files
committed
fix: delete hot100 add study plan list
1 parent bd291fd commit 9d7a22f

8 files changed

+56
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { graphql } from '#common/utils/http/graphql.js'
2+
import { getPlanQuestionListJson } from '#resources/headers/planQuestionListJson.js'
3+
4+
export async function getPlanQuestionList(slug) {
5+
const res = await graphql(getPlanQuestionListJson(slug))
6+
const {
7+
data: { studyPlanV2Detail }
8+
} = res
9+
return studyPlanV2Detail
10+
}

common/utils/question-getter/getQuestionListHot100.js

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { graphql } from '#common/utils/http/graphql.js'
2+
import { getStudyPlanListJson } from '#resources/headers/studyPlanListJson.js'
3+
4+
export async function getStudyPlanList() {
5+
const res = await graphql(getStudyPlanListJson())
6+
const {
7+
data: { studyPlansV2AdQuestionPage }
8+
} = res
9+
return studyPlansV2AdQuestionPage
10+
}

common/utils/question-handler/getHot100QuestionListCode.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import path from 'node:path'
22
import { createQuestionByTitleSlug } from '../create-check/createUtil.js'
3-
import { getQuestionListHot100 } from '#common/utils/question-getter/getQuestionListHot100.js'
3+
import { getPlanQuestionList } from '#common/utils/question-getter/getPlanQuestionList.js'
44

55
// 获取题目列表
66
export async function getTitleSlugList() {
7-
const res = await getQuestionListHot100()
7+
const res = await getPlanQuestionList()
88
const { planSubGroups } = res
99
return planSubGroups.reduce((acc, cur) => {
1010
acc.push(...cur.questions.map((res) => res.titleSlug))

common/view/finder.view.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import select from '@inquirer/select'
22
import input from '@inquirer/input'
33

4-
import {
5-
getHot100QuestionListCode,
6-
getTitleSlugList
7-
} from '#common/utils/question-handler/getHot100QuestionListCode.js'
4+
// import { getHot100QuestionListCode } from '#common/utils/question-handler/getHot100QuestionListCode.js'
85
import {
96
createQuestionById,
107
createQuestionByTitleSlug
118
} from '#common/utils/create-check/createUtil.js'
129
import { getQuestionByKeyword } from '#common/utils/question-getter/getQuestionByKeyword.js'
10+
import { getStudyPlanList } from '#common/utils/question-getter/getStudyPlanList.js'
11+
import { getPlanQuestionList } from '#common/utils/question-getter/getPlanQuestionList.js'
1312

14-
async function hotMode(baseDir = process.cwd()) {
13+
async function studyMode(baseDir = process.cwd()) {
14+
const questionList = await getStudyPlanList()
15+
const planListMode = {
16+
message: '请选择学习计划',
17+
choices: questionList.map((item) => ({
18+
name: `${item.name}${item.premiumOnly ? '(VIP)' : ''}`,
19+
value: item.slug
20+
}))
21+
}
22+
const planSlug = await select(planListMode)
1523
const createMode = await select({
1624
message: '拉题模式',
1725
choices: [
@@ -20,10 +28,14 @@ async function hotMode(baseDir = process.cwd()) {
2028
]
2129
})
2230
if (createMode === 'single') {
23-
const titleSlugList = await getTitleSlugList()
31+
const { planSubGroups } = await getPlanQuestionList(planSlug)
32+
const planList = planSubGroups.reduce((acc, cur) => {
33+
acc.push(...cur.questions.map((res) => res.titleSlug))
34+
return acc
35+
}, [])
2436
const singleMode = {
2537
message: '请选择题目?',
26-
choices: titleSlugList.map((res) => ({
38+
choices: planList.map((res) => ({
2739
name: res,
2840
value: res
2941
}))
@@ -32,7 +44,7 @@ async function hotMode(baseDir = process.cwd()) {
3244

3345
await createQuestionByTitleSlug(singleChoice, baseDir)
3446
}
35-
if (createMode === 'all') await getHot100QuestionListCode()
47+
// if (createMode === 'all') await getHot100QuestionListCode()
3648
}
3749

3850
async function keywordMode(baseDir = process.cwd()) {
@@ -54,18 +66,16 @@ async function keywordMode(baseDir = process.cwd()) {
5466
console.log(chooseQuestion)
5567
await createQuestionById(chooseQuestion, baseDir)
5668
}
69+
5770
async function selectMode(baseDir) {
71+
5872
console.log(baseDir)
5973
}
6074

6175
export async function easyFinderView(baseDir = process.cwd()) {
6276
const choices = [
6377
{ name: '关键词搜索', value: 'keyword', description: '关键词描述' },
64-
{
65-
name: 'hot 100列表查询',
66-
value: 'hot',
67-
description: '最受欢迎的100道题目'
68-
},
78+
{ name: '学习计划', value: 'study', description: '企业和经典面试题目列表' },
6979
{ name: '筛选模式', value: 'select', description: '筛选题目' }
7080
]
7181

@@ -76,7 +86,7 @@ export async function easyFinderView(baseDir = process.cwd()) {
7686
const mode = await select(modeQuestion)
7787

7888
const modeMap = {
79-
hot: hotMode,
89+
study: studyMode,
8090
keyword: keywordMode,
8191
select: selectMode
8292
}

resources/headers/questionListHot100Json.js resources/headers/planQuestionListJson.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* 获取hot 100 的请求header
33
* @returns {{headers: {"content-type": string}, method: string, body: string}}
44
*/
5-
export function getQuestionListHot100Json() {
5+
export function getPlanQuestionListJson(slug) {
66
return {
77
headers: { 'content-type': 'application/json' },
8-
body: '{"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"}',
8+
body: `{"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":"${slug}"},"operationName":"studyPlanPastSolved"}`,
99
method: 'POST'
1010
}
1111
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function getStudyPlanListJson() {
2+
return {
3+
headers: { 'content-type': 'application/json' },
4+
body: "{\"query\":\"\\n query GetProblemSetStudyPlanAds {\\n studyPlansV2AdQuestionPage {\\n cover\\n highlight\\n name\\n onGoing\\n premiumOnly\\n questionNum\\n slug\\n }\\n}\\n \",\"variables\":{},\"operationName\":\"GetProblemSetStudyPlanAds\"}",
5+
method: 'POST'
6+
}
7+
}

test/getHot100List.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import { getQuestionListHot100 } from '#common/utils/question-getter/getQuestionListHot100.js'
2+
import { getQuestionListHot100 } from '#common/utils/question-getter/getPlanQuestionList.js'
33

44
describe('hot 100获取数据测试', () => {
55
it('是否正确获取了hot 100合集', async () => {

0 commit comments

Comments
 (0)