mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: use common plugin-api interface
This commit is contained in:
1 parent
c61c875bee
commit
70a96aecac
54 files changed
+387
-566
No files matched your search
@@ -13,7 +13,7 @@ export interface RemoteAccount {
|
||||
problemLists?: string[];
|
||||
enableOn?: string[];
|
||||
}
|
||||
declare module 'hydrooj/src/interface' {
|
||||
declare module 'hydrooj' {
|
||||
interface Collections {
|
||||
vjudge: RemoteAccount;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import os from 'os';
|
||||
import { sleep } from '@hydrooj/utils/lib/utils';
|
||||
import * as Judge from 'hydrooj/src/handler/judge';
|
||||
import { Logger } from 'hydrooj/src/logger';
|
||||
import { STATUS } from 'hydrooj/src/model/builtin';
|
||||
import DomainModel from 'hydrooj/src/model/domain';
|
||||
import ProblemModel from 'hydrooj/src/model/problem';
|
||||
import TaskModel from 'hydrooj/src/model/task';
|
||||
import * as bus from 'hydrooj/src/service/bus';
|
||||
import db from 'hydrooj/src/service/db';
|
||||
import {
|
||||
Context, db, DomainModel, JudgeHandler, Logger,
|
||||
ProblemModel, sleep, STATUS, TaskModel,
|
||||
} from 'hydrooj';
|
||||
import { BasicProvider, IBasicProvider, RemoteAccount } from './interface';
|
||||
import { getDifficulty } from './providers/codeforces';
|
||||
import providers from './providers/index';
|
||||
@@ -40,8 +35,8 @@ class Service {
|
||||
}
|
||||
|
||||
async judge(task) {
|
||||
const next = (payload) => Judge.next({ ...payload, rid: task.rid });
|
||||
const end = (payload) => Judge.end({ ...payload, rid: task.rid });
|
||||
const next = (payload) => JudgeHandler.next({ ...payload, rid: task.rid });
|
||||
const end = (payload) => JudgeHandler.end({ ...payload, rid: task.rid });
|
||||
await next({ status: STATUS.STATUS_FETCHED });
|
||||
try {
|
||||
const rid = await this.api.submitProblem(task.target, task.lang, task.code, task, next, end);
|
||||
@@ -137,7 +132,7 @@ async function loadAccounts() {
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'hydrooj/src/interface' {
|
||||
declare module 'hydrooj' {
|
||||
interface Model {
|
||||
vjudge: VJudgeModel;
|
||||
}
|
||||
@@ -155,4 +150,6 @@ class VJudgeModel {
|
||||
|
||||
global.Hydro.model.vjudge = VJudgeModel;
|
||||
|
||||
bus.on('app/started', loadAccounts);
|
||||
export function apply(ctx: Context) {
|
||||
ctx.on('ready', loadAccounts);
|
||||
}
|
||||
@@ -9,11 +9,9 @@ import PortalPlugin from 'puppeteer-extra-plugin-portal';
|
||||
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
|
||||
import superagent from 'superagent';
|
||||
import proxy from 'superagent-proxy';
|
||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||
import { sleep } from '@hydrooj/utils/lib/utils';
|
||||
import { buildContent } from 'hydrooj/src/lib/content';
|
||||
import { Logger } from 'hydrooj/src/logger';
|
||||
import * as setting from 'hydrooj/src/model/setting';
|
||||
import {
|
||||
buildContent, Logger, SettingModel, sleep, STATUS,
|
||||
} from 'hydrooj';
|
||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||
import { VERDICT } from '../verdict';
|
||||
|
||||
@@ -386,7 +384,7 @@ export default class CodeforcesProvider implements IBasicProvider {
|
||||
|
||||
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;
|
||||
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}`;
|
||||
|
||||
@@ -3,9 +3,7 @@ import { PassThrough } from 'stream';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import * as superagent from 'superagent';
|
||||
import proxy from 'superagent-proxy';
|
||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||
import { sleep } from '@hydrooj/utils/lib/utils';
|
||||
import { Logger } from 'hydrooj/src/logger';
|
||||
import { Logger, sleep, STATUS } from 'hydrooj';
|
||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||
|
||||
proxy(superagent as any);
|
||||
|
||||
@@ -5,7 +5,7 @@ import poj from './poj';
|
||||
import spoj from './spoj';
|
||||
import uoj from './uoj';
|
||||
|
||||
declare module 'hydrooj/src/interface' {
|
||||
declare module 'hydrooj' {
|
||||
interface HydroGlobal {
|
||||
vjudge: typeof vjudge;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,9 @@ import { JSDOM } from 'jsdom';
|
||||
import { flattenDeep } from 'lodash';
|
||||
import superagent from 'superagent';
|
||||
import proxy from 'superagent-proxy';
|
||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||
import { sleep } from '@hydrooj/utils/lib/utils';
|
||||
import { Logger } from 'hydrooj/src/logger';
|
||||
import * as setting from 'hydrooj/src/model/setting';
|
||||
import {
|
||||
Logger, SettingModel, sleep, STATUS,
|
||||
} from 'hydrooj';
|
||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||
|
||||
proxy(superagent);
|
||||
@@ -104,7 +103,7 @@ export default class LuoguProvider implements IBasicProvider {
|
||||
|
||||
async submitProblem(id: string, lang: string, code: string, info, next, end) {
|
||||
let enableO2 = 0;
|
||||
const comment = setting.langs[lang]?.comment;
|
||||
const comment = SettingModel.langs[lang]?.comment;
|
||||
if (code.length < 10) {
|
||||
end({ status: STATUS.STATUS_COMPILE_ERROR, message: 'Code too short' });
|
||||
return null;
|
||||
|
||||
@@ -3,12 +3,9 @@ import { PassThrough } from 'stream';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import * as superagent from 'superagent';
|
||||
import proxy from 'superagent-proxy';
|
||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||
import {
|
||||
htmlEncode, parseMemoryMB, parseTimeMS, sleep,
|
||||
} from '@hydrooj/utils/lib/utils';
|
||||
import { Logger } from 'hydrooj/src/logger';
|
||||
import * as setting from 'hydrooj/src/model/setting';
|
||||
htmlEncode, Logger, parseMemoryMB, parseTimeMS, SettingModel, sleep, STATUS,
|
||||
} from 'hydrooj';
|
||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||
import { VERDICT } from '../verdict';
|
||||
|
||||
@@ -221,7 +218,7 @@ export default class POJProvider implements IBasicProvider {
|
||||
async submitProblem(id: string, lang: string, code: string, info) {
|
||||
await this.ensureLogin();
|
||||
const language = lang.includes('poj.') ? lang.split('poj.')[1] : '0';
|
||||
const comment = setting.langs[lang].comment;
|
||||
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}`;
|
||||
|
||||
@@ -3,10 +3,9 @@ import { PassThrough } from 'stream';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import superagent from 'superagent';
|
||||
import proxy from 'superagent-proxy';
|
||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||
import { parseMemoryMB, sleep } from '@hydrooj/utils/lib/utils';
|
||||
import { Logger } from 'hydrooj/src/logger';
|
||||
import * as setting from 'hydrooj/src/model/setting';
|
||||
import {
|
||||
Logger, parseMemoryMB, SettingModel, sleep, STATUS,
|
||||
} from 'hydrooj';
|
||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||
|
||||
proxy(superagent);
|
||||
@@ -118,7 +117,7 @@ langs: ${JSON.stringify(langs)}`),
|
||||
}
|
||||
|
||||
async submitProblem(problemcode: string, lang: string, code: string, info, next, end) {
|
||||
const comment = setting.langs[lang]?.comment;
|
||||
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}`;
|
||||
|
||||
@@ -3,10 +3,9 @@ import { PassThrough } from 'stream';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import * as superagent from 'superagent';
|
||||
import proxy from 'superagent-proxy';
|
||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||
import { parseMemoryMB, parseTimeMS, sleep } from '@hydrooj/utils/lib/utils';
|
||||
import { Logger } from 'hydrooj/src/logger';
|
||||
import * as setting from 'hydrooj/src/model/setting';
|
||||
import {
|
||||
Logger, parseMemoryMB, parseTimeMS, SettingModel, sleep, STATUS,
|
||||
} from 'hydrooj';
|
||||
import { IBasicProvider, RemoteAccount } from '../interface';
|
||||
import { VERDICT } from '../verdict';
|
||||
|
||||
@@ -165,7 +164,7 @@ export default class UOJProvider implements IBasicProvider {
|
||||
async submitProblem(id: string, lang: string, code: string, info) {
|
||||
let programTypeId = lang.includes('uoj.') ? lang.split('uoj.')[1] : 'C++11';
|
||||
if (programTypeId === 'Python27') programTypeId = 'Python2.7';
|
||||
const comment = setting.langs[lang].comment;
|
||||
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}`;
|
||||
|
||||
Reference in new issue
Block a user