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

Commit4aaad19

Browse files
feat: Add get lists and get questions of list (#17)
* feat: Add get lists method* feat: Add get questions of list* feat: Update version
1 parent5da642e commit4aaad19

File tree

8 files changed

+126
-10
lines changed

8 files changed

+126
-10
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.9.0",
3+
"version":"1.10.0",
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,31 @@ describe('LeetCode Advanced', { timeout: 60_000 * 60 }, () => {
144144
expect(parseInt(recentSubmission?.idasstring)).toBeGreaterThan(0);
145145
},
146146
);
147+
148+
it.skipIf(!process.env['TEST_LEETCODE_SESSION'])(
149+
'should be able to get leetcode lists of user',
150+
async()=>{
151+
constlists=awaitlc.getLists();
152+
expect(lists).not.toBeNull();
153+
expect(lists).toBeTruthy();
154+
expect(lists.length).greaterThan(10);
155+
expect(lists[0].slug).not.toBeNull();
156+
expect(lists[0].slug).toBeTruthy();
157+
expect(lists[0].slug.length).toBeGreaterThan(2);
158+
},
159+
);
160+
161+
it.skipIf(!process.env['TEST_LEETCODE_SESSION'])(
162+
'should be able to get questions of a leetcode list of user',
163+
async()=>{
164+
constquestions=awaitlc.getQuestionsOfList('rev4di7h');
165+
expect(questions).not.toBeNull();
166+
expect(questions).toBeTruthy();
167+
expect(questions.length).greaterThan(10);
168+
expect(questions[0].questionFrontendId).not.toBeNull();
169+
expect(questions[0].questionFrontendId).toBeTruthy();
170+
expect(questions[0].questionFrontendId.length).toBeGreaterThan(0);
171+
},
172+
);
147173
});
148174
});

‎src/_tests/leetcode.test.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,18 @@ describe('LeetCode', { timeout: 15_000 }, () => {
107107
},
108108
);
109109

110-
it.skipIf(!process.env['TEST_LEETCODE_SESSION'])(
111-
'should be able to get submission details',
112-
async()=>{
113-
constsubmission=awaitlc.submission(1416118091);
114-
expect(submission.id).toBe(1416118091);
115-
expect(submission.memory).toBe(18152000);
116-
expect(submission.runtime).toBe(8);
117-
},
118-
);
110+
/**
111+
* Disabled because doesn't work sometimes due to cloudflare issue
112+
*/
113+
114+
// it.skipIf(!process.env['TEST_LEETCODE_SESSION'])(
115+
// 'should be able to get submission details',
116+
// async () => {
117+
// const submission = await lc.submission(1416118091);
118+
// expect(submission.id).toBe(1416118091);
119+
// expect(submission.memory).toBe(18152000);
120+
// expect(submission.runtime).toBe(8);
121+
// },
122+
// );
119123
});
120124
});

‎src/graphql/lists.graphql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
querymyFavoriteList {
2+
myCreatedFavoriteList {
3+
favorites {
4+
name
5+
slug
6+
}
7+
hasMore
8+
totalLength
9+
}
10+
}

‎src/graphql/questions-of-list.graphql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
queryfavoriteQuestionList($favoriteSlug:String!,$filter:FavoriteQuestionFilterInput) {
2+
favoriteQuestionList(favoriteSlug:$favoriteSlug,filter:$filter) {
3+
questions {
4+
questionFrontendId
5+
status
6+
title
7+
titleSlug
8+
translatedTitle
9+
isInMyFavorites
10+
frequency
11+
topicTags {
12+
name
13+
slug
14+
}
15+
}
16+
totalLength
17+
hasMore
18+
}
19+
}

‎src/leetcode-advanced.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import COLLECT_EASTER_EGG from './graphql/collect-easter-egg.graphql?raw';
66
importCOMPANY_TAGSfrom'./graphql/company-tags.graphql?raw';
77
importLEETCODE_PROBLEMS_QUERYfrom'./graphql/custom-problem.graphql?raw';
88
importIS_EASTER_EGG_COLLECTEDfrom'./graphql/is-easter-egg-collected.graphql?raw';
9+
importLISTSfrom'./graphql/lists.graphql?raw';
910
importMINIMAL_COMPANY_TAGSfrom'./graphql/minimal-company-tags.graphql?raw';
1011
importNO_OF_QUESTIONSfrom'./graphql/no-of-problems.graphql?raw';
1112
importQUESTION_FRONTEND_IDSfrom'./graphql/question-frontend-ids.graphql?raw';
13+
importQUESTIONS_OF_LISTfrom'./graphql/questions-of-list.graphql?raw';
1214
importTITLE_SLUG_QUESTION_NUMBER_MAPPING_QUERYfrom'./graphql/title-slug-question-number-mapping.graphql?raw';
1315
importTOPIC_TAGSfrom'./graphql/topic-tags.graphql?raw';
1416
import{LeetCode}from'./leetcode';
@@ -18,6 +20,7 @@ import {
1820
DetailedProblem,
1921
EasterEggStatus,
2022
LeetcodeProblem,
23+
List,
2124
MinimalCompanyTagDetail,
2225
ProblemFieldDetails,
2326
QueryParams,
@@ -26,6 +29,7 @@ import {
2629
UserSubmission,
2730
}from'./leetcode-types';
2831
importproblemPropertiesfrom'./problem-properties';
32+
import{QuestionOfList}from'./types';
2933

3034
exportclassLeetCodeAdvancedextendsLeetCode{
3135
problemProperties=problemProperties;
@@ -189,6 +193,36 @@ export class LeetCodeAdvanced extends LeetCode {
189193
returndata.problemsetQuestionList.totalasnumber;
190194
}
191195

196+
/**
197+
* Get leetcode lists of the user
198+
* Need to be authenticated
199+
*@returns array of leetcode lists
200+
*/
201+
publicasyncgetLists():Promise<Array<List>>{
202+
awaitthis.initialized;
203+
const{ data}=awaitthis.graphql({
204+
query:LISTS,
205+
});
206+
returndata.myCreatedFavoriteList.favoritesasArray<List>;
207+
}
208+
209+
/**
210+
* Get all questions of a leetcode list
211+
* Need to be authenticated
212+
*@param slug slug id of the leetcode list
213+
*@returns array of questions
214+
*/
215+
publicasyncgetQuestionsOfList(slug:string):Promise<Array<QuestionOfList>>{
216+
awaitthis.initialized;
217+
const{ data}=awaitthis.graphql({
218+
query:QUESTIONS_OF_LIST,
219+
variables:{
220+
favoriteSlug:slug,
221+
},
222+
});
223+
returndata.favoriteQuestionList.questionsasArray<QuestionOfList>;
224+
}
225+
192226
publicasyncgetProblemTypes():Promise<Record<string,string[]>>{
193227
constproblemTypes:Record<string,string[]>={};
194228
for(constcategoryofPROBLEM_CATEGORIES){

‎src/leetcode-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,8 @@ export interface DailyChallenge {
491491
link:string;
492492
question:Problem;
493493
}
494+
495+
exportinterfaceList{
496+
name:string;
497+
slug:string;
498+
}

‎src/types.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,21 @@ export interface LeetCodeGraphQLResponse {
5353
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5454
data:UserProfile|UserSubmission[]|any;
5555
}
56+
57+
exportinterfaceQuestionOfList{
58+
difficulty:string;
59+
id:number;
60+
paidOnly:boolean;
61+
questionFrontendId:string;
62+
status:string;
63+
title:string;
64+
titleSlug:string;
65+
topicTags:Array<{
66+
title:string;
67+
slug:string;
68+
}>;
69+
isInMyFavorites:boolean;
70+
frequency:number|null;
71+
acRate:number|null;
72+
__typename:string;
73+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp