From abbeff3dbc93f6a7fa42648246a74cb3ca2aa443 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 10 Apr 2023 22:29:52 +0800 Subject: [PATCH] vjudge: ybtbas --- packages/vjudge/src/providers/hustoj.ts | 40 +++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/vjudge/src/providers/hustoj.ts b/packages/vjudge/src/providers/hustoj.ts index 50292987..701a06a5 100644 --- a/packages/vjudge/src/providers/hustoj.ts +++ b/packages/vjudge/src/providers/hustoj.ts @@ -18,7 +18,7 @@ interface HustOJRemoteConfig { endpoint?: string; usernameField?: string; passwordField?: string; - extra?: Record; + extra?: Record | (() => Promise>); }; // NOTE: CAPTCHAS ARE NOT SUPPORTED submit?: { @@ -83,6 +83,10 @@ const defaultConfig: HustOJRemoteConfig = { function isProcessing(t: string) { return [STATUS.STATUS_WAITING, STATUS.STATUS_COMPILING, STATUS.STATUS_JUDGING].includes(VERDICT[t]); } +// TODO +async function parseCaptcha(image: Buffer) { // eslint-disable-line + return ''; +} export class HUSTOJ extends BasicFetcher implements IBasicProvider { config: HustOJRemoteConfig; @@ -118,10 +122,11 @@ export class HUSTOJ extends BasicFetcher implements IBasicProvider { async login(username: string, password: string) { this.cookie = []; - const res = await this.post(this.config.login[0]).send({ - [this.config.login.usernameField]: username, - [this.config.login.passwordField]: password, - ...this.config.login.extra, + const c = this.config.login; + const res = await this.post(c.endpoint).send({ + [c.usernameField]: username, + [c.passwordField]: password, + ...(typeof c.extra === 'function' ? await c.extra() : c.extra), }); this.state.username = username; this.cookie = res.headers['set-cookie'].join('\n'); @@ -289,6 +294,31 @@ export class YBT extends HUSTOJ { } } +export class YBTBAS extends HUSTOJ { + updateConfig() { + this.config.login.extra = async () => { + const captcha = await this.get('/login_xx.php').responseType('arraybuffer'); + return { + login: '登录', + auth: (await parseCaptcha(captcha.body)).toLowerCase(), + }; + }; + this.config.submit = { + endpoint: '/action.php', + idField: 'problem_id', + langField: 'language', + codeField: 'source', + extra: { submit: '提交', user_id: this.account.handle }, + tooFrequent: '提交频繁啦!', + }; + this.config.ceInfo = { + endpoint: '/show_ce_info.php?runid={rid}', + matcher: /(.*?)<\/td>/gmi, + }; + this.config.server = 'http://bas.ssoier.cn:8086/'; + } +} + export class BZOJ extends HUSTOJ { updateConfig() { this.config.login = {