|
1 | 1 | const axios = require('axios'); |
2 | 2 | const { Octokit } = require('@octokit/rest'); |
3 | | -const fetch = require("node-fetch"); |
4 | 3 |
|
5 | 4 | const COMMIT_MESSAGE = 'Sync LeetCode submission'; |
6 | 5 | const LANG_TO_EXTENSION = { |
@@ -64,7 +63,7 @@ async function commit(params) { |
64 | 63 | { |
65 | 64 | path, |
66 | 65 | mode: '100644', |
67 | | - content: question_data + '\n' + '# Solution' + '\n' + '```' + submission.lang + ' \n' + submission.code + '\n' + '```', |
| 66 | + content: question_data + '\n \n ' + '# Solution' + '\n' + '```' + submission.lang + ' \n' + submission.code + '\n' + '```', |
68 | 67 | } |
69 | 68 | ]; |
70 | 69 |
|
@@ -124,18 +123,11 @@ async function getQuestionData(titleSlug, leetcodeSession) { |
124 | 123 | variables: {"titleSlug": titleSlug}, |
125 | 124 | }) |
126 | 125 |
|
127 | | - const requestOptions = { |
128 | | - method: 'POST', |
129 | | - headers, |
130 | | - body: graphql, |
131 | | - redirect: 'follow' |
132 | | - }; |
133 | 126 |
|
134 | 127 | try { |
135 | | - const response = await fetch("https://leetcode.com/graphql/", requestOptions); |
136 | | - const result = await response.text(); |
137 | | - const parsedResult = JSON.parse(result); |
138 | | - return parsedResult.data.question.content; |
| 128 | + const response = await axios.post("https://leetcode.com/graphql/", graphql, {headers}); |
| 129 | + const result = await response.data; |
| 130 | + return result.data.question.content; |
139 | 131 | } catch (error) { |
140 | 132 | console.log('error', error); |
141 | 133 | } |
|
0 commit comments