forked from discord/discord-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemOfTheDay.js
More file actions
72 lines (64 loc) · 1.78 KB
/
problemOfTheDay.js
File metadata and controls
72 lines (64 loc) · 1.78 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import https from 'https';
const csrfToken = 'wBQw3cRfDaU0dXrFRhkPFX2d0N1lUXq4IjQ1LCqQxM1VwGYOwHiqKXrgmXnlAAxf';
const data = JSON.stringify({
query: `
query questionOfToday {
activeDailyCodingChallengeQuestion {
date
userStatus
link
question {
acRate
difficulty
freqBar
frontendQuestionId: questionFrontendId
isFavor
paidOnly: isPaidOnly
status
title
titleSlug
hasVideoSolution
hasSolution
topicTags {
name
id
slug
}
}
}
}
`,
variables: {},
operationName: "questionOfToday",
csrfToken: csrfToken // Including CSRF token in the request body if needed
});
const options = {
hostname: 'leetcode.com',
port: 443,
path: '/graphql/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Referer': 'https://leetcode.com/problemset/',
'X-CSRFToken': csrfToken // Including CSRF token in the request headers
}
};
export async function getProblemOfTheDay() {
return new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
let responseBody = '';
res.on('data', (chunk) => {
responseBody += chunk;
});
res.on('end', () => {
resolve(responseBody);
});
});
req.on('error', (e) => {
reject(`Problem with request: ${e.message}`);
});
// Write data to request body and end the request
req.write(data);
req.end();
});
}