mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
vjudge: codeforces: handle submission error
This commit is contained in:
1 parent
c6c4a80549
commit
72290bd5be
2 files changed
+15
-10
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/vjudge",
|
"name": "@hydrooj/vjudge",
|
||||||
"version": "1.5.0-next.7",
|
"version": "1.5.0-next.8",
|
||||||
"description": "Submit problems to remote oj",
|
"description": "Submit problems to remote oj",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
async checkLogin() {
|
async checkLogin() {
|
||||||
await this.ensureBrowser();
|
await this.ensureBrowser();
|
||||||
const page = await this.getPage();
|
const page = await this.getPage();
|
||||||
await page.goto(`${this.account.endpoint}/enter`, { waitUntil: 'networkidle2' });
|
await page.goto(`${this.account.endpoint}/enter`, { waitUntil: 'networkidle2', timeout: 180000 });
|
||||||
const html = await page.content();
|
const html = await page.content();
|
||||||
let cookies = await page.cookies();
|
let cookies = await page.cookies();
|
||||||
let c = 0;
|
let c = 0;
|
||||||
@@ -179,12 +179,10 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get loggedIn() {
|
get loggedIn() {
|
||||||
return this.puppeteer
|
return this.get('/enter').then(({ text: html }) => {
|
||||||
? this.checkLogin().then(([, , loggedIn]) => loggedIn)
|
if (html.includes('Login into Codeforces')) return false;
|
||||||
: this.get('/enter').then(({ text: html }) => {
|
return true;
|
||||||
if (html.includes('Login into Codeforces')) return false;
|
});
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async normalLogin() {
|
async normalLogin() {
|
||||||
@@ -360,7 +358,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async submitProblem(id: string, lang: string, code: string, info) {
|
async submitProblem(id: string, lang: string, code: string, info, next, end) {
|
||||||
const programTypeId = lang.includes('codeforces.') ? lang.split('codeforces.')[1] : '54';
|
const programTypeId = lang.includes('codeforces.') ? lang.split('codeforces.')[1] : '54';
|
||||||
const comment = setting.langs[lang].comment;
|
const comment = setting.langs[lang].comment;
|
||||||
if (comment) {
|
if (comment) {
|
||||||
@@ -373,7 +371,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
? '/problemset/submit'
|
? '/problemset/submit'
|
||||||
: `/gym/${contestId}/submit`);
|
: `/gym/${contestId}/submit`);
|
||||||
// TODO check submit time to ensure submission
|
// TODO check submit time to ensure submission
|
||||||
await this.post(`/${type !== 'GYM' ? 'problemset' : `gym/${contestId}`}/submit?csrf_token=${csrf}`).send({
|
const { text: submit } = await this.post(`/${type !== 'GYM' ? 'problemset' : `gym/${contestId}`}/submit?csrf_token=${csrf}`).send({
|
||||||
csrf_token: csrf,
|
csrf_token: csrf,
|
||||||
action: 'submitSolutionFormSubmitted',
|
action: 'submitSolutionFormSubmitted',
|
||||||
programTypeId,
|
programTypeId,
|
||||||
@@ -391,6 +389,13 @@ export default class CodeforcesProvider implements IBasicProvider {
|
|||||||
submittedProblemIndex: problemId,
|
submittedProblemIndex: problemId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const { window: { document: statusDocument } } = new JSDOM(submit);
|
||||||
|
const message = Array.from(statusDocument.querySelectorAll('.error'))
|
||||||
|
.map((i) => i.textContent).join('').replace(/ /g, ' ').trim();
|
||||||
|
if (message) {
|
||||||
|
end({ status: STATUS.STATUS_COMPILE_ERROR, message });
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const { text: status } = await this.get(type !== 'GYM'
|
const { text: status } = await this.get(type !== 'GYM'
|
||||||
? '/problemset/status?my=on'
|
? '/problemset/status?my=on'
|
||||||
: `/gym/${contestId}/my`);
|
: `/gym/${contestId}/my`);
|
||||||
|
|||||||
Reference in new issue
Block a user