File tree 12 files changed +82
-7
lines changed
12 files changed +82
-7
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 基础请求
3
+ * @param url
4
+ * @param options
5
+ * @returns {Promise<any> }
6
+ * @private
7
+ */
8
+ export const fetch_ = async ( url , options ) => {
9
+ return await fetch ( url , options ) . then ( res => res . json ( ) )
10
+ }
Original file line number Diff line number Diff line change
1
+ import path from "path" ;
2
+ import { fetch_ } from "#common/utils/http/fetch_.js" ;
3
+
4
+ /**
5
+ * 请求
6
+ * @param options
7
+ * @param host
8
+ * @returns {Promise<any> }
9
+ */
10
+ export const graphql = async ( options , host = "https://leetcode.cn/" ) => {
11
+ return await fetch_ ( path . join ( host , 'graphql' ) , options ) ;
12
+ }
Original file line number Diff line number Diff line change
1
+ import { fetch_ } from "#common/utils/http/fetch_.js" ;
2
+ import path from "path" ;
3
+
4
+ /**
5
+ * 请求
6
+ * @param options
7
+ * @param host
8
+ * @returns {Promise<any> }
9
+ */
10
+ export const submit = async ( options , host = "https://leetcode.cn/" ) => {
11
+ return await fetch_ ( path . join ( host , 'submit' ) , options ) ;
12
+ }
Original file line number Diff line number Diff line change 1
1
import { getQuestionSearchJson } from "#resources/headers/questionSearchJson.js" ;
2
2
import { getQuestionDetail } from "../question-handler/getQuestionDetail.js" ;
3
+ import { graphql } from "#common/utils/http/graphql.js" ;
3
4
export async function getQuestionById ( id ) {
4
- const base = await fetch ( 'https://leetcode.cn/ graphql/' , getQuestionSearchJson ( id . toString ( ) ) ) . then ( ( res ) => res . json ( ) ) ;
5
+ const base = await graphql ( getQuestionSearchJson ( id . toString ( ) ) ) . then ( ( res ) => res . json ( ) ) ;
5
6
const questionContent = base . data . problemsetQuestionList . questions . find ( ( o ) => o . frontendQuestionId === id . toString ( ) ) ;
6
7
if ( ! questionContent ) {
7
8
return {
Original file line number Diff line number Diff line change 1
1
import { getQuestionListJson } from "#resources/headers/questionListJson.js" ;
2
+ import { graphql } from "#common/utils/http/graphql.js" ;
2
3
3
4
export async function getQuestionList ( ) {
4
- const base = await fetch ( 'https://leetcode.cn/graphql/' , getQuestionListJson ( ) ) . then ( ( res ) => res . json ( ) ) ;
5
+ const base = await graphql ( getQuestionListJson ( ) ) . then ( ( res ) => res . json ( ) ) ;
6
+ // todo 列表
7
+ const question = base . questions ;
5
8
return question ;
6
9
}
Original file line number Diff line number Diff line change 1
1
import { getQuestionSearchJson } from "#resources/headers/questionSearchJson.js" ;
2
2
import { getQuestionDetail } from "../question-handler/getQuestionDetail.js" ;
3
3
import { getRandomId } from "#common/utils/question-handler/getRandomId.js" ;
4
+ import { graphql } from "#common/utils/http/graphql.js" ;
4
5
5
6
export async function getQuestionRandom ( ) {
6
7
const id = await getRandomId ( )
7
- const base = await fetch ( 'https://leetcode.cn/ graphql/' , getQuestionSearchJson ( id . toString ( ) ) ) . then ( ( res ) => res . json ( ) ) ;
8
+ const base = await graphql ( getQuestionSearchJson ( id . toString ( ) ) ) . then ( ( res ) => res . json ( ) ) ;
8
9
const slug = base . data . problemsetQuestionList . questions . find ( ( o ) => o . frontendQuestionId === id . toString ( ) ) . titleSlug ;
9
10
const question = await getQuestionDetail ( slug ) ;
10
11
return question ;
Original file line number Diff line number Diff line change 1
1
import { getQuestionTodayJson } from "#resources/headers/questionTodayJson.js" ;
2
2
import { getQuestionDetail } from "../question-handler/getQuestionDetail.js" ;
3
+ import { graphql } from "#common/utils/http/graphql.js" ;
3
4
4
5
export async function getQuestionToday ( ) {
5
- const question = await fetch ( 'https://leetcode.cn/ graphql/' , getQuestionTodayJson ( ) ) . then ( ( ( res ) => res . json ( ) ) ) ;
6
+ const question = await graphql ( getQuestionTodayJson ( ) ) . then ( ( ( res ) => res . json ( ) ) ) ;
6
7
const today = question . data . todayRecord [ 0 ] . question ;
7
8
const { date } = question . data . todayRecord [ 0 ] ;
8
9
const questionInfo = await getQuestionDetail ( today . titleSlug , { date } ) ;
Original file line number Diff line number Diff line change 1
1
import { getQuestionTypesJson } from "#resources/headers/questionTypeJson.js" ;
2
+ import { graphql } from "#common/utils/http/graphql.js" ;
2
3
3
4
/**
4
5
* 获取问题的类型
@@ -22,7 +23,7 @@ import {getQuestionTypesJson} from "#resources/headers/questionTypeJson.js";
22
23
* @returns {Promise<*> }
23
24
*/
24
25
export async function getQuestionTypes ( ) {
25
- const res = await fetch ( 'https://leetcode.cn/ graphql/' , getQuestionTypesJson ( ) ) . then ( ( res ) => res . json ( ) ) ;
26
+ const res = await graphql ( getQuestionTypesJson ( ) ) . then ( ( res ) => res . json ( ) ) ;
26
27
const tags = res . data ?. questionTagTypeWithTags ;
27
28
// console.log(JSON.stringify(tags))
28
29
return tags ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import inquirer from "inquirer";
2
2
import path from "path" ;
3
3
import { getQuestionFileName } from "#common/utils/question-handler/getQuestionFileName.js" ;
4
4
import { getQuestionById } from "#common/utils/question-getter/getQuestionById.js" ;
5
- import { getQuestionByMode } from "#common/utils/store/store-realm .js" ;
5
+ import { getQuestionByMode } from "#common/utils/store/controller/question .js" ;
6
6
import { checkQuestion } from "#common/utils/question-handler/checkQuestion.js" ;
7
7
import { getCountBySameName } from "#common/utils/file/getCountBySameName.js" ;
8
8
import { getFileListBySameName } from "#common/utils/file/getFileListBySameName.js" ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import {getQuestionToday} from "#common/utils/question-getter/getQuestionToday.j
6
6
import { getQuestionRandom } from "#common/utils/question-getter/getQuestionRandom.js" ;
7
7
import { createQuestion } from "#common/utils/question-handler/createQuestion.js" ;
8
8
import { createQuestionCopy } from "#common/utils/question-handler/createQuestionCopy.js" ;
9
- import { setQuestion } from "#common/utils/store/store-realm .js" ;
9
+ import { setQuestion } from "#common/utils/store/controller/question .js" ;
10
10
export const easyCreateView = async ( ) => {
11
11
const modeQuestion = [ {
12
12
type : 'list' ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 提交请求的JSON数据
3
+ * 地址:https://leetcode.cn/problems/reverse-integer/submit/
4
+ * @param lang
5
+ * @param id
6
+ * @param code
7
+ * @returns {{headers: {"content-type": string}, method: string, body: string} }
8
+ */
9
+ export function codeSubmitJson ( lang , id , code ) {
10
+ return {
11
+ headers : { "content-type" : "application/json" } ,
12
+ body : `{
13
+ "lang": "${ lang } ",
14
+ "question_id": "${ id } ",
15
+ "typed_code": "${ code } "
16
+ }` ,
17
+ method : 'POST' ,
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 获取当前语言列表
3
+ * @returns {{headers: {"content-type": string}, method: string, body: string} }
4
+ */
5
+ export function getQuestionLanguageListJson ( ) {
6
+ return {
7
+ headers : { "content-type" : "application/json" } ,
8
+ body : `{
9
+ "query": "\\n query languageList {\\n languageList {\\n id\\n name\\n }\\n}\\n ",
10
+ "variables": {},
11
+ "operationName": "languageList"
12
+ }` ,
13
+ method : 'POST' ,
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments