-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_example_testcases.js
41 lines (33 loc) · 973 Bytes
/
get_example_testcases.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
async function getQuestionData(titleSlug, dataType, vscode) {
const url = "https://leetcode.com/graphql";
const query = `
query questionContent($titleSlug: String!) {
question(titleSlug: $titleSlug) {
content
}
}
`;
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query: query,
variables: { titleSlug },
}),
});
const data = await response.json();
if (!response.ok) {
vscode.window.showErrorMessage("Error fetching question content:", data.errors ? data.errors[0].message:"Check Internet Connection");
return null;
}
const result = data.data.question["content"];
return result;
} catch (error) {
vscode.window.showErrorMessage("Error fetching question content:", "Provide valid URL");
return null;
}
};
module.exports = { getQuestionData };