mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
vjudge: merge comment tool
This commit is contained in:
7 files changed
+16
-47
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
import {
|
import {
|
||||||
Context, db, DomainModel, JudgeHandler, Logger,
|
Context, db, DomainModel, JudgeHandler, Logger,
|
||||||
ProblemModel, RecordModel, Service, sleep, STATUS, TaskModel, Time,
|
ProblemModel, RecordModel, Service, SettingModel, sleep, STATUS, TaskModel, Time,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { BasicProvider, IBasicProvider, RemoteAccount } from './interface';
|
import { BasicProvider, IBasicProvider, RemoteAccount } from './interface';
|
||||||
import providers from './providers/index';
|
import providers from './providers/index';
|
||||||
@@ -39,6 +39,12 @@ class AccountService {
|
|||||||
const end = (payload) => JudgeHandler.end({ ...payload, rid: task.rid });
|
const end = (payload) => JudgeHandler.end({ ...payload, rid: task.rid });
|
||||||
await next({ status: STATUS.STATUS_FETCHED });
|
await next({ status: STATUS.STATUS_FETCHED });
|
||||||
try {
|
try {
|
||||||
|
const comment = SettingModel.langs[task.lang].comment;
|
||||||
|
if (comment) {
|
||||||
|
const msg = `Hydro submission #${task.rid}@${new Date().getTime()}`;
|
||||||
|
if (typeof comment === 'string') task.code = `${comment} ${msg}\n${task.code}`;
|
||||||
|
else if (comment instanceof Array) task.code = `${comment[0]} ${msg} ${comment[1]}\n${task.code}`;
|
||||||
|
}
|
||||||
const rid = await this.api.submitProblem(task.target, task.lang, task.code, task, next, end);
|
const rid = await this.api.submitProblem(task.target, task.lang, task.code, task, next, end);
|
||||||
if (!rid) return;
|
if (!rid) return;
|
||||||
await next({ status: STATUS.STATUS_JUDGING, message: `ID = ${rid}` });
|
await next({ status: STATUS.STATUS_JUDGING, message: `ID = ${rid}` });
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { PassThrough } from 'stream';
|
|||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import {
|
import {
|
||||||
buildContent, Logger, SettingModel, sleep, STATUS,
|
buildContent, Logger, sleep, STATUS,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { BasicFetcher } from '../fetch';
|
import { BasicFetcher } from '../fetch';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||||
@@ -272,12 +272,6 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
|
|||||||
|
|
||||||
async submitProblem(id: string, lang: string, code: string, info, next, end) {
|
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 = SettingModel.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 [type, contestId, problemId] = parseProblemId(id);
|
const [type, contestId, problemId] = parseProblemId(id);
|
||||||
const endpoint = type === 'GYM'
|
const endpoint = type === 'GYM'
|
||||||
? `/gym/${contestId}/submit`
|
? `/gym/${contestId}/submit`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
_, Logger, SettingModel, sleep, STATUS,
|
_, Logger, sleep, STATUS,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { BasicFetcher } from '../fetch';
|
import { BasicFetcher } from '../fetch';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||||
@@ -134,16 +134,9 @@ export class HUSTOJ extends BasicFetcher implements IBasicProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async submitProblem(id: string, lang: string, code: string, info, next) {
|
async submitProblem(id: string, lang: string, code: string, info, next) {
|
||||||
const langId = lang.split('.')[1];
|
|
||||||
const comment = SettingModel.langs[lang].comment;
|
|
||||||
if (comment) {
|
|
||||||
const msg = `Hydro submission #${info.rid}@${Date.now()}`;
|
|
||||||
if (typeof comment === 'string') code = `${comment} ${msg}\n${code}`;
|
|
||||||
else if (comment instanceof Array) code = `${comment[0]} ${msg} ${comment[1]}\n${code}`;
|
|
||||||
}
|
|
||||||
const res = await this.post(this.config.submit.endpoint).send({
|
const res = await this.post(this.config.submit.endpoint).send({
|
||||||
[this.config.submit.idField]: id,
|
[this.config.submit.idField]: id,
|
||||||
[this.config.submit.langField]: langId,
|
[this.config.submit.langField]: lang.split('.')[1],
|
||||||
[this.config.submit.codeField]: code,
|
[this.config.submit.codeField]: code,
|
||||||
...this.config.submit.extra,
|
...this.config.submit.extra,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
import {
|
import {
|
||||||
_, Logger, SettingModel, sleep, STATUS,
|
_, Logger, sleep, STATUS,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { BasicFetcher } from '../fetch';
|
import { BasicFetcher } from '../fetch';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||||
@@ -87,7 +87,6 @@ export default class LuoguProvider extends BasicFetcher implements IBasicProvide
|
|||||||
|
|
||||||
async submitProblem(id: string, lang: string, code: string, info, next, end) {
|
async submitProblem(id: string, lang: string, code: string, info, next, end) {
|
||||||
let enableO2 = 0;
|
let enableO2 = 0;
|
||||||
const comment = SettingModel.langs[lang]?.comment;
|
|
||||||
if (code.length < 10) {
|
if (code.length < 10) {
|
||||||
end({ status: STATUS.STATUS_COMPILE_ERROR, message: 'Code too short' });
|
end({ status: STATUS.STATUS_COMPILE_ERROR, message: 'Code too short' });
|
||||||
return null;
|
return null;
|
||||||
@@ -96,11 +95,6 @@ export default class LuoguProvider extends BasicFetcher implements IBasicProvide
|
|||||||
end({ status: STATUS.STATUS_COMPILE_ERROR, message: `Language not supported: ${lang}` });
|
end({ status: STATUS.STATUS_COMPILE_ERROR, message: `Language not supported: ${lang}` });
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (comment) {
|
|
||||||
const msg = `Hydro submission #${info.rid}@${new Date().toLocaleString()}`;
|
|
||||||
if (typeof comment === 'string') code = `${comment} ${msg}\n${code}`;
|
|
||||||
else if (comment instanceof Array) code = `${comment[0]} ${msg} ${comment[1]}\n${code}`;
|
|
||||||
}
|
|
||||||
if (lang.endsWith('o2')) {
|
if (lang.endsWith('o2')) {
|
||||||
enableO2 = 1;
|
enableO2 = 1;
|
||||||
lang = lang.slice(0, -2);
|
lang = lang.slice(0, -2);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { PassThrough } from 'stream';
|
import { PassThrough } from 'stream';
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import {
|
import {
|
||||||
htmlEncode, Logger, parseMemoryMB, parseTimeMS, SettingModel, sleep, STATUS,
|
htmlEncode, Logger, parseMemoryMB, parseTimeMS, sleep, STATUS,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { BasicFetcher } from '../fetch';
|
import { BasicFetcher } from '../fetch';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||||
@@ -195,15 +195,9 @@ export default class POJProvider extends BasicFetcher implements IBasicProvider
|
|||||||
.map((i) => `P${+i.children[0].innerHTML ? i.children[0].innerHTML : i.children[1].innerHTML}`);
|
.map((i) => `P${+i.children[0].innerHTML ? i.children[0].innerHTML : i.children[1].innerHTML}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async submitProblem(id: string, lang: string, code: string, info) {
|
async submitProblem(id: string, lang: string, code: string) {
|
||||||
await this.ensureLogin();
|
await this.ensureLogin();
|
||||||
const language = lang.includes('poj.') ? lang.split('poj.')[1] : '0';
|
const language = lang.includes('poj.') ? lang.split('poj.')[1] : '0';
|
||||||
const comment = SettingModel.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}`;
|
|
||||||
}
|
|
||||||
code = Buffer.from(code).toString('base64');
|
code = Buffer.from(code).toString('base64');
|
||||||
const { text } = await this.post('/submit').send({
|
const { text } = await this.post('/submit').send({
|
||||||
problem_id: id.split('P')[1],
|
problem_id: id.split('P')[1],
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { PassThrough } from 'stream';
|
import { PassThrough } from 'stream';
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import {
|
import {
|
||||||
Logger, parseMemoryMB, SettingModel, sleep, STATUS,
|
Logger, parseMemoryMB, sleep, STATUS,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { BasicFetcher } from '../fetch';
|
import { BasicFetcher } from '../fetch';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||||
@@ -94,12 +94,6 @@ langs: ${JSON.stringify(langs)}`),
|
|||||||
}
|
}
|
||||||
|
|
||||||
async submitProblem(problemcode: string, lang: string, code: string, info, next, end) {
|
async submitProblem(problemcode: string, lang: string, code: string, info, next, end) {
|
||||||
const comment = SettingModel.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}`;
|
|
||||||
}
|
|
||||||
// TODO check submit time to ensure submission
|
// TODO check submit time to ensure submission
|
||||||
const { text } = await this.post('/submit/complete/').send({
|
const { text } = await this.post('/submit/complete/').send({
|
||||||
submit: 'Submit!',
|
submit: 'Submit!',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { PassThrough } from 'stream';
|
import { PassThrough } from 'stream';
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import {
|
import {
|
||||||
Logger, parseMemoryMB, parseTimeMS, SettingModel, sleep, STATUS,
|
Logger, parseMemoryMB, parseTimeMS, sleep, STATUS,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { BasicFetcher } from '../fetch';
|
import { BasicFetcher } from '../fetch';
|
||||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||||
@@ -142,15 +142,9 @@ export default class UOJProvider extends BasicFetcher implements IBasicProvider
|
|||||||
return Array.from($dom.window.document.querySelectorAll('tbody>tr>td>a')).map((i) => `P${i.getAttribute('href').split('/')[4]}`);
|
return Array.from($dom.window.document.querySelectorAll('tbody>tr>td>a')).map((i) => `P${i.getAttribute('href').split('/')[4]}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async submitProblem(id: string, lang: string, code: string, info) {
|
async submitProblem(id: string, lang: string, code: string) {
|
||||||
let programTypeId = lang.includes('uoj.') ? lang.split('uoj.')[1] : 'C++11';
|
let programTypeId = lang.includes('uoj.') ? lang.split('uoj.')[1] : 'C++11';
|
||||||
if (programTypeId === 'Python27') programTypeId = 'Python2.7';
|
if (programTypeId === 'Python27') programTypeId = 'Python2.7';
|
||||||
const comment = SettingModel.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 _token = await this.getCsrfToken(`/problem/${id.split('P')[1]}`);
|
const _token = await this.getCsrfToken(`/problem/${id.split('P')[1]}`);
|
||||||
const { text } = await this.post(`/problem/${id.split('P')[1]}`).send({
|
const { text } = await this.post(`/problem/${id.split('P')[1]}`).send({
|
||||||
_token,
|
_token,
|
||||||
|
|||||||
Reference in new issue
Block a user