From 72290bd5bee61e710bb65fd324a9ac8b8401fb73 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 27 Aug 2022 17:58:02 +0800 Subject: [PATCH] vjudge: codeforces: handle submission error --- packages/vjudge/package.json | 2 +- packages/vjudge/src/providers/codeforces.ts | 23 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/vjudge/package.json b/packages/vjudge/package.json index eaef7462b..1cf59ad65 100644 --- a/packages/vjudge/package.json +++ b/packages/vjudge/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/vjudge", - "version": "1.5.0-next.7", + "version": "1.5.0-next.8", "description": "Submit problems to remote oj", "main": "package.json", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/vjudge/src/providers/codeforces.ts b/packages/vjudge/src/providers/codeforces.ts index 064fcd843..43e1e36ba 100644 --- a/packages/vjudge/src/providers/codeforces.ts +++ b/packages/vjudge/src/providers/codeforces.ts @@ -142,7 +142,7 @@ export default class CodeforcesProvider implements IBasicProvider { async checkLogin() { await this.ensureBrowser(); 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(); let cookies = await page.cookies(); let c = 0; @@ -179,12 +179,10 @@ export default class CodeforcesProvider implements IBasicProvider { } get loggedIn() { - return this.puppeteer - ? this.checkLogin().then(([, , loggedIn]) => loggedIn) - : this.get('/enter').then(({ text: html }) => { - if (html.includes('Login into Codeforces')) return false; - return true; - }); + return this.get('/enter').then(({ text: html }) => { + if (html.includes('Login into Codeforces')) return false; + return true; + }); } 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 comment = setting.langs[lang].comment; if (comment) { @@ -373,7 +371,7 @@ export default class CodeforcesProvider implements IBasicProvider { ? '/problemset/submit' : `/gym/${contestId}/submit`); // 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, action: 'submitSolutionFormSubmitted', programTypeId, @@ -391,6 +389,13 @@ export default class CodeforcesProvider implements IBasicProvider { 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' ? '/problemset/status?my=on' : `/gym/${contestId}/my`);