Skip to content

Commit 3f83267

Browse files
author
xusupeng
committed
refactor(explorer): 重构 Hot100 和 Interview Classics 150 的获取方式
-从 explorerNodeManager.ts 中移除直接调用接口获取 Hot100 和 Interview Classics 150 数据的逻辑 - 在 LeetCodeNode.ts 中添加 isHot100 和 isClassic150属性,用于判断节点是否属于 Hot100 或 Classic150 - 更新 list.ts,将 Hot100 和 Interview Classics 150 的数据作为问题列表的一部分进行处理 - 在 shared.ts 中为 IProblem 接口添加 isHot100 和 isClassic150 字段 暂存
1 parent 586b3e4 commit 3f83267

File tree

6 files changed

+310
-1
lines changed

6 files changed

+310
-1
lines changed

src/commands/list.ts

Lines changed: 258 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,269 @@ import { IProblem, ProblemState, UserStatus } from "../shared";
77
import * as settingUtils from "../utils/settingUtils";
88
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";
99

10+
1011
export async function listProblems(): Promise<IProblem[]> {
1112
try {
1213
if (leetCodeManager.getStatus() === UserStatus.SignedOut) {
1314
return [];
1415
}
1516

1617
const useEndpointTranslation: boolean = settingUtils.shouldUseEndpointTranslation();
17-
const result: string = await leetCodeExecutor.listProblems(true, useEndpointTranslation);
18+
let result = await leetCodeExecutor.listProblems(true, useEndpointTranslation);
19+
let classic150Problems = [
20+
88,
21+
27,
22+
26,
23+
80,
24+
169,
25+
189,
26+
121,
27+
122,
28+
55,
29+
45,
30+
274,
31+
380,
32+
238,
33+
134,
34+
135,
35+
42,
36+
13,
37+
12,
38+
58,
39+
14,
40+
151,
41+
6,
42+
28,
43+
68,
44+
125,
45+
392,
46+
167,
47+
11,
48+
15,
49+
209,
50+
3,
51+
30,
52+
76,
53+
36,
54+
54,
55+
48,
56+
73,
57+
289,
58+
383,
59+
205,
60+
290,
61+
242,
62+
49,
63+
1,
64+
202,
65+
219,
66+
128,
67+
228,
68+
56,
69+
57,
70+
452,
71+
20,
72+
71,
73+
155,
74+
150,
75+
224,
76+
141,
77+
2,
78+
21,
79+
138,
80+
92,
81+
25,
82+
19,
83+
82,
84+
61,
85+
86,
86+
146,
87+
104,
88+
100,
89+
226,
90+
101,
91+
105,
92+
106,
93+
117,
94+
114,
95+
112,
96+
129,
97+
124,
98+
173,
99+
222,
100+
236,
101+
199,
102+
637,
103+
102,
104+
103,
105+
530,
106+
230,
107+
98,
108+
200,
109+
130,
110+
133,
111+
399,
112+
207,
113+
210,
114+
945,
115+
433,
116+
127,
117+
208,
118+
211,
119+
212,
120+
17,
121+
77,
122+
46,
123+
39,
124+
52,
125+
22,
126+
79,
127+
108,
128+
148,
129+
772,
130+
23,
131+
53,
132+
954,
133+
35,
134+
74,
135+
162,
136+
33,
137+
34,
138+
153,
139+
4,
140+
215,
141+
502,
142+
373,
143+
295,
144+
67,
145+
190,
146+
191,
147+
136,
148+
137,
149+
201,
150+
9,
151+
66,
152+
172,
153+
69,
154+
50,
155+
149,
156+
70,
157+
198,
158+
139,
159+
322,
160+
300,
161+
120,
162+
64,
163+
63,
164+
5,
165+
97,
166+
72,
167+
123,
168+
188,
169+
221
170+
];
171+
let hot100Problems = [
172+
1,
173+
49,
174+
128,
175+
283,
176+
11,
177+
15,
178+
42,
179+
3,
180+
438,
181+
560,
182+
239,
183+
76,
184+
53,
185+
56,
186+
189,
187+
238,
188+
41,
189+
73,
190+
54,
191+
48,
192+
240,
193+
160,
194+
206,
195+
234,
196+
141,
197+
142,
198+
21,
199+
2,
200+
19,
201+
24,
202+
25,
203+
138,
204+
148,
205+
23,
206+
146,
207+
94,
208+
104,
209+
226,
210+
101,
211+
543,
212+
102,
213+
108,
214+
98,
215+
230,
216+
199,
217+
114,
218+
105,
219+
437,
220+
236,
221+
124,
222+
200,
223+
1036,
224+
207,
225+
208,
226+
46,
227+
78,
228+
17,
229+
39,
230+
22,
231+
79,
232+
131,
233+
51,
234+
35,
235+
74,
236+
34,
237+
33,
238+
153,
239+
4,
240+
20,
241+
155,
242+
394,
243+
739,
244+
84,
245+
215,
246+
347,
247+
295,
248+
121,
249+
55,
250+
45,
251+
768,
252+
70,
253+
118,
254+
198,
255+
279,
256+
322,
257+
139,
258+
300,
259+
152,
260+
416,
261+
32,
262+
62,
263+
64,
264+
5,
265+
1250,
266+
72,
267+
136,
268+
169,
269+
75,
270+
31,
271+
287
272+
]
18273
const problems: IProblem[] = [];
19274
const lines: string[] = result.split("\n");
20275
const reg: RegExp = /^(.)\s(.{1,2})\s(.)\s\[\s*(\d*)\s*\]\s*(.*)\s*(Easy|Medium|Hard)\s*\((\s*\d+\.\d+ %)\)/;
@@ -28,6 +283,8 @@ export async function listProblems(): Promise<IProblem[]> {
28283
isFavorite: match[1].trim().length > 0,
29284
locked: match[2].trim().length > 0,
30285
state: parseProblemState(match[3]),
286+
isHot100: hot100Problems.includes(Number(id)),
287+
isClassic150: classic150Problems.includes(Number(id)),
31288
name: match[5].trim(),
32289
difficulty: match[6].trim(),
33290
passRate: match[7].trim(),

src/explorer/LeetCodeNode.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export class LeetCodeNode {
4242
public get isFavorite(): boolean {
4343
return this.data.isFavorite;
4444
}
45+
public get isHot100(): boolean {
46+
return this.data.isHot100;
47+
}
48+
public get isClassic150(): boolean {
49+
return this.data.isClassic150;
50+
}
4551

4652
public get isProblem(): boolean {
4753
return this.isProblemNode;

src/explorer/LeetCodeTreeDataProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
8585
return explorerNodeManager.getAllTagNodes();
8686
case Category.Company:
8787
return explorerNodeManager.getAllCompanyNodes();
88+
case Category.Hot100:
89+
return explorerNodeManager.getHot100Nodes();
90+
case Category.InterviewClassics150Problems:
91+
return explorerNodeManager.getInterviewClassics150Nodes();
8892
default:
8993
if (element.isProblem) {
9094
return [];

src/explorer/explorerNodeManager.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ class ExplorerNodeManager implements Disposable {
5353
id: Category.Favorite,
5454
name: Category.Favorite,
5555
}), false),
56+
new LeetCodeNode(Object.assign({}, defaultProblem, {
57+
id: Category.Hot100,
58+
name: Category.Hot100,
59+
}), false),
60+
new LeetCodeNode(Object.assign({}, defaultProblem, {
61+
id: Category.InterviewClassics150Problems,
62+
name: Category.InterviewClassics150Problems,
63+
}), false),
5664
];
5765
}
5866

@@ -106,6 +114,26 @@ class ExplorerNodeManager implements Disposable {
106114
return res;
107115
}
108116

117+
public getHot100Nodes(): LeetCodeNode[] {
118+
const res: LeetCodeNode[] = [];
119+
for (const node of this.explorerNodeMap.values()) {
120+
if (node.isHot100) {
121+
res.push(node);
122+
}
123+
}
124+
return this.applySortingStrategy(res);
125+
}
126+
127+
public getInterviewClassics150Nodes(): LeetCodeNode[] {
128+
const res: LeetCodeNode[] = [];
129+
for (const node of this.explorerNodeMap.values()) {
130+
if (node.isClassic150) {
131+
res.push(node);
132+
}
133+
}
134+
return this.applySortingStrategy(res);
135+
}
136+
109137
public getNodeById(id: string): LeetCodeNode | undefined {
110138
return this.explorerNodeMap.get(id);
111139
}

src/leetCodeExecutor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ class LeetCodeExecutor implements Disposable {
198198
await this.executeCommandWithProgressEx("Updating the favorite list...", "node", commandParams);
199199
}
200200

201+
public async fetchHot100Problems(): Promise<string> {
202+
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "custom", "--url", "https://leetcode.cn/_next/data/LdkbymEZAqp5oj7_FRWLn/studyplan/top-100-liked.json?slug=top-100-liked"]);
203+
}
204+
205+
public async fetchInterviewClassics150Problems(): Promise<string> {
206+
return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "custom", "--url", "https://leetcode.cn/_next/data/LdkbymEZAqp5oj7_FRWLn/studyplan/top-interview-150.json?slug=top-interview-150"]);
207+
}
208+
201209
public async getCompaniesAndTags(): Promise<{ companies: { [key: string]: string[] }, tags: { [key: string]: string[] } }> {
202210
// preprocess the plugin source
203211
const companiesTagsPath: string = path.join(this.leetCodeRootPath, "lib", "plugins", "company.js");

src/shared.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export enum Endpoint {
7373

7474
export interface IProblem {
7575
isFavorite: boolean;
76+
isHot100: boolean;
77+
isClassic150: boolean;
7678
locked: boolean;
7779
state: ProblemState;
7880
id: string;
@@ -87,6 +89,8 @@ export const defaultProblem: IProblem = {
8789
isFavorite: false,
8890
locked: false,
8991
state: ProblemState.Unknown,
92+
isHot100: false,
93+
isClassic150: false,
9094
id: "",
9195
name: "",
9296
difficulty: "",
@@ -101,6 +105,8 @@ export enum Category {
101105
Tag = "Tag",
102106
Company = "Company",
103107
Favorite = "Favorite",
108+
Hot100 = "Hot100",
109+
InterviewClassics150Problems = "InterviewClassics150Problems",
104110
}
105111

106112
export const supportedPlugins: string[] = ["company", "solution.discuss", "leetcode.cn"];

0 commit comments

Comments
 (0)