Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita8d2f36

Browse files
feat: add getTitleSlugQuestionNumberMapping method (#15)
1 parent51e4e68 commita8d2f36

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"@leetnotion/leetcode-api",
3-
"version":"1.8.3",
3+
"version":"1.8.4",
44
"description":"Get user profiles, submissions, and problems on LeetCode.",
55
"type":"module",
66
"types":"lib/index.d.ts",

‎src/_tests/leetcode-advanced.test.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,22 @@ describe('LeetCode Advanced', { timeout: 60_000 * 60 }, () => {
7373
expect(problems.length).toBeGreaterThan(3000);
7474
});
7575

76-
// it('should be able to get detailed problems', async () => {
77-
// const problems = await lc.detailedProblems({
78-
// category: '',
79-
// offset: 0,
80-
// limit: 10,
81-
// });
82-
// expect(problems.length).equals(10);
83-
// expect(problems[0].questionFrontendId).toBeTruthy();
84-
// expect(problems[0].title).toBeTruthy();
85-
// expect(problems[0].difficulty).toBeTruthy();
86-
// });
76+
it('should be able to get title slug question number mapping',async()=>{
77+
constmapping=awaitlc.getTitleSlugQuestionNumberMapping();
78+
expect(Object.keys(mapping).length).toBeGreaterThan(3000);
79+
});
80+
81+
it('should be able to get detailed problems',async()=>{
82+
constproblems=awaitlc.detailedProblems({
83+
category:'',
84+
offset:0,
85+
limit:10,
86+
});
87+
expect(problems.length).equals(10);
88+
expect(problems[0].questionFrontendId).toBeTruthy();
89+
expect(problems[0].title).toBeTruthy();
90+
expect(problems[0].difficulty).toBeTruthy();
91+
});
8792
});
8893

8994
describe('Authenticated',()=>{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
queryproblemsetQuestionList(
2+
$categorySlug:String
3+
$limit:Int
4+
$skip:Int
5+
$filters:QuestionListFilterInput
6+
) {
7+
problemsetQuestionList:questionList(
8+
categorySlug:$categorySlug
9+
limit:$limit
10+
skip:$skip
11+
filters:$filters
12+
) {
13+
total:totalNum
14+
questions:data {
15+
questionFrontendId
16+
titleSlug
17+
}
18+
}
19+
}

‎src/leetcode-advanced.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import IS_EASTER_EGG_COLLECTED from './graphql/is-easter-egg-collected.graphql?r
99
importMINIMAL_COMPANY_TAGSfrom'./graphql/minimal-company-tags.graphql?raw';
1010
importNO_OF_QUESTIONSfrom'./graphql/no-of-problems.graphql?raw';
1111
importQUESTION_FRONTEND_IDSfrom'./graphql/question-frontend-ids.graphql?raw';
12+
importTITLE_SLUG_QUESTION_NUMBER_MAPPING_QUERYfrom'./graphql/title-slug-question-number-mapping.graphql?raw';
1213
importTOPIC_TAGSfrom'./graphql/topic-tags.graphql?raw';
1314
import{LeetCode}from'./leetcode';
1415
import{
@@ -365,6 +366,29 @@ export class LeetCodeAdvanced extends LeetCode {
365366
returnproblems;
366367
}
367368

369+
/**
370+
* Get title slug question number mapping for all leetcode questions
371+
*@returns Mapping
372+
*/
373+
publicasyncgetTitleSlugQuestionNumberMapping():Promise<Record<string,string>>{
374+
awaitthis.initialized;
375+
const{ data}=awaitthis.graphql({
376+
query:TITLE_SLUG_QUESTION_NUMBER_MAPPING_QUERY,
377+
variables:{
378+
categorySlug:'',
379+
filters:{},
380+
skip:0,
381+
limit:100000,
382+
},
383+
});
384+
constproblems=data.problemsetQuestionList.questionsasLeetcodeProblem[];
385+
constmapping:Record<string,string>={};
386+
problems.forEach((problem)=>{
387+
mapping[problem.titleSlug]=problem.questionFrontendId;
388+
});
389+
returnmapping;
390+
}
391+
368392
privateconvertRecentSubmissionToSubmissionType(recentSubmission:RecentSubmission):Submission{
369393
return{
370394
id:parseInt(recentSubmission.id,10),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp