mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 16:08:42 +00:00
fix(remote_judger/luogu): sec cookie
This commit is contained in:
parent
5cfd8d5846
commit
4de24c44e0
42
remote_judger/package-lock.json
generated
42
remote_judger/package-lock.json
generated
@ -12,6 +12,7 @@
|
|||||||
"crlf-normalize": "^1.0.18",
|
"crlf-normalize": "^1.0.18",
|
||||||
"fs-extra": "^11.1.0",
|
"fs-extra": "^11.1.0",
|
||||||
"jsdom": "^21.0.0",
|
"jsdom": "^21.0.0",
|
||||||
|
"lodash.flattendeep": "^4.4.0",
|
||||||
"math-sum": "^2.0.0",
|
"math-sum": "^2.0.0",
|
||||||
"reggol": "^1.3.4",
|
"reggol": "^1.3.4",
|
||||||
"superagent": "^8.0.6",
|
"superagent": "^8.0.6",
|
||||||
@ -21,6 +22,7 @@
|
|||||||
"@types/fs-extra": "^11.0.1",
|
"@types/fs-extra": "^11.0.1",
|
||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/jsdom": "^20.0.1",
|
"@types/jsdom": "^20.0.1",
|
||||||
|
"@types/lodash.flattendeep": "^4.4.7",
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
"@types/superagent": "^4.1.16",
|
"@types/superagent": "^4.1.16",
|
||||||
"@types/superagent-proxy": "^3.0.0",
|
"@types/superagent-proxy": "^3.0.0",
|
||||||
@ -78,6 +80,21 @@
|
|||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/lodash": {
|
||||||
|
"version": "4.14.191",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.191.tgz",
|
||||||
|
"integrity": "sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"node_modules/@types/lodash.flattendeep": {
|
||||||
|
"version": "4.4.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/lodash.flattendeep/-/lodash.flattendeep-4.4.7.tgz",
|
||||||
|
"integrity": "sha512-1h6GW/AeZw/Wej6uxrqgmdTDZX1yFS39lRsXYkg+3kWvOWWrlGCI6H7lXxlUHOzxDT4QeYGmgPpQ3BX9XevzOg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/lodash": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "18.11.18",
|
"version": "18.11.18",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
|
||||||
@ -790,6 +807,11 @@
|
|||||||
"node": ">= 0.8.0"
|
"node": ">= 0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/lodash.flattendeep": {
|
||||||
|
"version": "4.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz",
|
||||||
|
"integrity": "sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ=="
|
||||||
|
},
|
||||||
"node_modules/lru-cache": {
|
"node_modules/lru-cache": {
|
||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
||||||
@ -1567,6 +1589,21 @@
|
|||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/lodash": {
|
||||||
|
"version": "4.14.191",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.191.tgz",
|
||||||
|
"integrity": "sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"@types/lodash.flattendeep": {
|
||||||
|
"version": "4.4.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/lodash.flattendeep/-/lodash.flattendeep-4.4.7.tgz",
|
||||||
|
"integrity": "sha512-1h6GW/AeZw/Wej6uxrqgmdTDZX1yFS39lRsXYkg+3kWvOWWrlGCI6H7lXxlUHOzxDT4QeYGmgPpQ3BX9XevzOg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/lodash": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "18.11.18",
|
"version": "18.11.18",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
|
||||||
@ -2113,6 +2150,11 @@
|
|||||||
"type-check": "~0.3.2"
|
"type-check": "~0.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"lodash.flattendeep": {
|
||||||
|
"version": "4.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz",
|
||||||
|
"integrity": "sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ=="
|
||||||
|
},
|
||||||
"lru-cache": {
|
"lru-cache": {
|
||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
"crlf-normalize": "^1.0.18",
|
"crlf-normalize": "^1.0.18",
|
||||||
"fs-extra": "^11.1.0",
|
"fs-extra": "^11.1.0",
|
||||||
"jsdom": "^21.0.0",
|
"jsdom": "^21.0.0",
|
||||||
|
"lodash.flattendeep": "^4.4.0",
|
||||||
"math-sum": "^2.0.0",
|
"math-sum": "^2.0.0",
|
||||||
"reggol": "^1.3.4",
|
"reggol": "^1.3.4",
|
||||||
"superagent": "^8.0.6",
|
"superagent": "^8.0.6",
|
||||||
@ -24,6 +25,7 @@
|
|||||||
"@types/fs-extra": "^11.0.1",
|
"@types/fs-extra": "^11.0.1",
|
||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/jsdom": "^20.0.1",
|
"@types/jsdom": "^20.0.1",
|
||||||
|
"@types/lodash.flattendeep": "^4.4.7",
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
"@types/superagent": "^4.1.16",
|
"@types/superagent": "^4.1.16",
|
||||||
"@types/superagent-proxy": "^3.0.0",
|
"@types/superagent-proxy": "^3.0.0",
|
||||||
|
@ -4,7 +4,7 @@ import proxy from 'superagent-proxy';
|
|||||||
import Logger from '../utils/logger';
|
import Logger from '../utils/logger';
|
||||||
import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface';
|
import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface';
|
||||||
import sleep from '../utils/sleep';
|
import sleep from '../utils/sleep';
|
||||||
import flattenDeep from '../utils/flattenDeep';
|
import flattenDeep from 'lodash.flattendeep';
|
||||||
|
|
||||||
proxy(superagent);
|
proxy(superagent);
|
||||||
const logger = new Logger('remote/luogu');
|
const logger = new Logger('remote/luogu');
|
||||||
@ -106,6 +106,23 @@ export default class LuoguProvider implements IBasicProvider {
|
|||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async safeGet(url: string) {
|
||||||
|
const res = await this.get(url);
|
||||||
|
|
||||||
|
if (res.text.startsWith('<html><script>document.location.reload()')) {
|
||||||
|
const sec = this.getCookie.call(
|
||||||
|
{ cookie: res.header['set-cookie'] },
|
||||||
|
'sec'
|
||||||
|
);
|
||||||
|
this.setCookie('sec', sec);
|
||||||
|
logger.debug('sec', sec);
|
||||||
|
|
||||||
|
return await this.get(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
post(url: string) {
|
post(url: string) {
|
||||||
logger.debug('post', url, this.cookie);
|
logger.debug('post', url, this.cookie);
|
||||||
|
|
||||||
@ -125,8 +142,21 @@ export default class LuoguProvider implements IBasicProvider {
|
|||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCookie(target: string) {
|
||||||
|
return this.cookie
|
||||||
|
.find(i => i.startsWith(`${target}=`))
|
||||||
|
?.split('=')[1]
|
||||||
|
?.split(';')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
setCookie(target: string, value: string) {
|
||||||
|
this.cookie = this.cookie.filter(i => !i.startsWith(`${target}=`));
|
||||||
|
this.cookie.push(`${target}=${value}`);
|
||||||
|
}
|
||||||
|
|
||||||
async getCsrfToken(url: string) {
|
async getCsrfToken(url: string) {
|
||||||
const { text: html } = await this.get(url);
|
let { text: html } = await this.safeGet(url);
|
||||||
|
|
||||||
const $dom = new JSDOM(html);
|
const $dom = new JSDOM(html);
|
||||||
|
|
||||||
this.csrf = $dom.window.document
|
this.csrf = $dom.window.document
|
||||||
@ -137,7 +167,7 @@ export default class LuoguProvider implements IBasicProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get loggedIn() {
|
get loggedIn() {
|
||||||
return this.get('/user/setting?_contentOnly=1').then(
|
return this.safeGet('/user/setting?_contentOnly=1').then(
|
||||||
({ body }) => body.currentTemplate !== 'AuthLogin'
|
({ body }) => body.currentTemplate !== 'AuthLogin'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -208,17 +238,15 @@ export default class LuoguProvider implements IBasicProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async waitForSubmission(problem_id: string, id: string, next, end) {
|
async waitForSubmission(problem_id: string, id: string, next, end) {
|
||||||
const done = {};
|
|
||||||
let fail = 0;
|
let fail = 0;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
let finished = 0;
|
|
||||||
|
|
||||||
while (count < 120 && fail < 5) {
|
while (count < 120 && fail < 5) {
|
||||||
await sleep(1500);
|
await sleep(1500);
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { body } = await this.get(`/record/${id}?_contentOnly=1`);
|
const { body } = await this.safeGet(`/record/${id}?_contentOnly=1`);
|
||||||
const data = body.currentData.record;
|
const data = body.currentData.record;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -227,41 +255,36 @@ export default class LuoguProvider implements IBasicProvider {
|
|||||||
) {
|
) {
|
||||||
return await end({
|
return await end({
|
||||||
error: true,
|
error: true,
|
||||||
id,
|
id: 'R' + id,
|
||||||
status: 'Compile Error',
|
status: 'Compile Error',
|
||||||
message: data.detail.compileResult.message,
|
message: data.detail.compileResult.message,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('Fetched with length', JSON.stringify(body).length);
|
logger.info('Fetched with length', JSON.stringify(body).length);
|
||||||
const total = flattenDeep(body.currentData.testCaseGroup).length;
|
const total = flattenDeep(
|
||||||
|
Object.entries(body.currentData.testCaseGroup || {}).map(o => o[1])
|
||||||
// TODO sorted
|
).length;
|
||||||
|
|
||||||
if (!data.detail.judgeResult?.subtasks) continue;
|
if (!data.detail.judgeResult?.subtasks) continue;
|
||||||
|
|
||||||
for (const key in data.detail.judgeResult.subtasks) {
|
|
||||||
const subtask = data.detail.judgeResult.subtasks[key];
|
|
||||||
for (const cid in subtask.testCases || {}) {
|
|
||||||
if (done[`${subtask.id}.${cid}`]) continue;
|
|
||||||
finished++;
|
|
||||||
done[`${subtask.id}.${cid}`] = true;
|
|
||||||
await next({
|
await next({
|
||||||
status: `Judging (${(finished / total) * 100})`,
|
status: `Judging (${
|
||||||
|
data.detail.judgeResult?.finishedCaseCount || '?'
|
||||||
|
}/${total})`,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.status < 2) continue;
|
if (data.status < 2) continue;
|
||||||
|
|
||||||
logger.info('RecordID:', id, 'done');
|
logger.info('RecordID:', id, 'done');
|
||||||
|
|
||||||
// TODO calc total status
|
|
||||||
|
|
||||||
return await end({
|
return await end({
|
||||||
id: 'R' + id,
|
id: 'R' + id,
|
||||||
status: STATUS_MAP[data.status],
|
status: STATUS_MAP[data.status],
|
||||||
score: data.score,
|
score:
|
||||||
|
STATUS_MAP[data.status] === 'Accepted'
|
||||||
|
? 100
|
||||||
|
: (data.score / data.problem.fullScore) * 100,
|
||||||
time: data.time,
|
time: data.time,
|
||||||
memory: data.memory,
|
memory: data.memory,
|
||||||
});
|
});
|
||||||
@ -274,6 +297,7 @@ export default class LuoguProvider implements IBasicProvider {
|
|||||||
|
|
||||||
return await end({
|
return await end({
|
||||||
error: true,
|
error: true,
|
||||||
|
id: 'R' + id,
|
||||||
status: 'Judgment Failed',
|
status: 'Judgment Failed',
|
||||||
message: 'Failed to fetch submission details.',
|
message: 'Failed to fetch submission details.',
|
||||||
});
|
});
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
const flattenDeep = arr =>
|
|
||||||
Array.isArray(arr)
|
|
||||||
? arr.reduce((a, b) => a.concat(flattenDeep(b)), [])
|
|
||||||
: [arr];
|
|
||||||
|
|
||||||
export default flattenDeep;
|
|
Loading…
Reference in New Issue
Block a user