From a09d7b4b7076201eadc87f92fd444a6bd145e625 Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 22 Jun 2021 12:32:47 +0800 Subject: [PATCH] vjudge: handle same-code-submission --- packages/vjudge/package.json | 2 +- packages/vjudge/src/interface.ts | 2 +- packages/vjudge/src/model.ts | 2 +- packages/vjudge/src/providers/codeforces.ts | 13 ++++++++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/vjudge/package.json b/packages/vjudge/package.json index 3bc909b07..417a9d6c2 100644 --- a/packages/vjudge/package.json +++ b/packages/vjudge/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/vjudge", - "version": "1.0.10", + "version": "1.0.11", "description": "Submit problems to remote oj", "main": "package.json", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/vjudge/src/interface.ts b/packages/vjudge/src/interface.ts index 7492e2d32..0d31c2ec7 100644 --- a/packages/vjudge/src/interface.ts +++ b/packages/vjudge/src/interface.ts @@ -25,7 +25,7 @@ export interface IBasicProvider { content: string; }>; listProblem(page: number): Promise; - submitProblem(id: string, lang: string, code: string): Promise; + submitProblem(id: string, lang: string, code: string, info): Promise; waitForSubmission(id: string, next: any, end: any): Promise; } diff --git a/packages/vjudge/src/model.ts b/packages/vjudge/src/model.ts index 6422aaf56..7ed0c31d2 100644 --- a/packages/vjudge/src/model.ts +++ b/packages/vjudge/src/model.ts @@ -26,7 +26,7 @@ class Service { } async judge(task) { - const rid = await this.api.submitProblem(task.target, task.lang, task.code); + const rid = await this.api.submitProblem(task.target, task.lang, task.code, task); const next = (payload) => Judge.next({ ...payload, rid: task.rid }); const end = (payload) => Judge.end({ ...payload, rid: task.rid }); await this.api.waitForSubmission(rid, next, end); diff --git a/packages/vjudge/src/providers/codeforces.ts b/packages/vjudge/src/providers/codeforces.ts index 02ff099c5..65cb5540f 100644 --- a/packages/vjudge/src/providers/codeforces.ts +++ b/packages/vjudge/src/providers/codeforces.ts @@ -4,6 +4,7 @@ import { JSDOM } from 'jsdom'; import { STATUS } from '@hydrooj/utils/lib/status'; import { sleep } from '@hydrooj/utils/lib/utils'; import { buildContent } from 'hydrooj/dist/lib/content'; +import * as setting from 'hydrooj/dist/model/setting'; import { Logger } from 'hydrooj/dist/logger'; import { PassThrough } from 'stream'; import { IBasicProvider, RemoteAccount } from '../interface'; @@ -189,8 +190,14 @@ export default class CodeforcesProvider implements IBasicProvider { return Array.from($dom.window.document.querySelectorAll('.id>a')).map((i) => `P${i.innerHTML.trim()}`); } - async submitProblem(id: string, lang: string, code: string) { + async submitProblem(id: string, lang: string, code: string, info) { const programTypeId = lang.includes('codeforces.') ? lang.split('codeforces.')[1] : '42'; + const comment = setting.langs[lang].comment; + if (comment) { + const msg = `Hydro submission #${info.rid}@${new Date().getTime()}`; + if (typeof comment === 'string') code = `${comment} ${msg}\n${code}`; + else if (comment instanceof Array) code = `${comment[0]} ${msg} ${comment[1]}\n${code}`; + } const [, contestId, submittedProblemIndex] = id.startsWith('P921') ? ['', '921', id.split('P921')[1]] : /^P(\d+)([A-Z][0-9]*)$/.exec(id); @@ -210,8 +217,8 @@ export default class CodeforcesProvider implements IBasicProvider { _tta: 594, sourceCodeConfirmed: true, }); - const { text: info } = await this.get('/problemset/status?my=on'); - const $dom = new JSDOM(info); + const { text: status } = await this.get('/problemset/status?my=on'); + const $dom = new JSDOM(status); this.csrf = $dom.window.document.querySelector('meta[name="X-Csrf-Token"]').getAttribute('content'); return $dom.window.document.querySelector('[data-submission-id]').getAttribute('data-submission-id'); }