File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 11async function fetchLeetCodeTags ( slug ) {
22 const query = {
3- query : `\n query getQuestionDetail($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n topicTags { name slug }\n }\n }\n ` ,
3+ query : `query getQuestionDetail($titleSlug: String!) { question(titleSlug: $titleSlug) { topicTags { name slug } } } ` ,
44 variables : { titleSlug : slug } ,
55 } ;
66
@@ -17,3 +17,29 @@ async function fetchLeetCodeTags(slug) {
1717 const data = await response . json ( ) ;
1818 return data . data ?. question ?. topicTags ?. map ( ( tag ) => tag . name ) || [ ] ;
1919}
20+
21+ async function fetchLeetCodeProblemData ( slug ) {
22+ const query = {
23+ query : `query getQuestionDetail($titleSlug: String!) { question(titleSlug: $titleSlug) { title difficulty topicTags { name slug } } }` ,
24+ variables : { titleSlug : slug } ,
25+ } ;
26+
27+ const response = await fetch ( "https://leetcode.com/graphql" , {
28+ method : "POST" ,
29+ headers : {
30+ "Content-Type" : "application/json" ,
31+ } ,
32+ body : JSON . stringify ( query ) ,
33+ credentials : "same-origin" ,
34+ } ) ;
35+
36+ if ( ! response . ok ) return null ;
37+ const data = await response . json ( ) ;
38+ const q = data . data ?. question ;
39+ if ( ! q ) return null ;
40+ return {
41+ title : q . title ,
42+ difficulty : q . difficulty ,
43+ tags : q . topicTags ?. map ( ( tag ) => tag . name ) || [ ] ,
44+ } ;
45+ }
You can’t perform that action at this time.
0 commit comments