-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
70 lines (63 loc) · 2.22 KB
/
main.js
File metadata and controls
70 lines (63 loc) · 2.22 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
import request from 'request';
import config from './config.mjs';
const { token, cookie, tries } = config;
import problems from './data.mjs';
const reqwest = async (mode, id) => {
return new Promise((res, rej) => {
const options = {
url: `https://anyview.gdut.edu.cn/api/gdb-service/code/${mode}`,
method: 'POST',
strictSSL: false,
headers: {
'Token': token,
'User-Agent': 'KeqingMoe-Hack/11.45.14',
'Content-Type': 'multipart/form-data',
'Cookie': cookie,
},
};
let form = request(options, (error, response, body) => {
if (error) {
rej(error);
} else {
res(JSON.parse(body).data);
}
}).form();
form.append('questionFullName', 'CP01EX025');
form.append('eID', `${id}`);
form.append('isTeacher', 'false');
form.append('kind', '4');
form.append('stuCode', '#include <iostream>\nint main(){std::cout<<"=RIGHT=";}');
form.append('questionRes.questionFullName', '第1章-CP01EX025');
form.append('language', '1');
form.append('isDebug', 'false');
});
};
const solve = async (id, name, n) => {
const progress=`[ ${n} / ${problems.length} ]`;
try {
let cr = await reqwest('compile', id);
if (cr.result != '编译成功<br>') {
console.log(`${progress} 题目 ${name} 编译失败,跳过。`);
return;
}
} catch (e) {
console.log(`${progress} 对题目 ${name} 调用编译接口时出现异常,跳过。`);
return;
}
for (let i = 0; i < tries; ++i) {
try {
let rr = await reqwest('runGroup', id);
if (rr.passed) {
console.log(`${progress} 题目 ${name} 尝试 ${i + 1} 次后通过。`);
return;
}
} catch (e) {
console.log(`${progress} 对题目 ${name} 调用评测接口时出现异常,重试。`);
}
}
console.log(`${progress} 题目 ${name} 尝试 ${tries} 次无法 hack,跳过。`);
};
let n = 0;
for (let [id, name] of problems) {
await solve(id, name, ++n);
}