From 186fcf0f34df720d103d9038b1dabc19e748d4a3 Mon Sep 17 00:00:00 2001 From: undefined Date: Sun, 28 Sep 2025 16:13:32 +0800 Subject: [PATCH] vjudge: better vedict --- packages/vjudge/src/fetch.ts | 4 ++-- packages/vjudge/src/verdict.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/vjudge/src/fetch.ts b/packages/vjudge/src/fetch.ts index dbd3e4258..461d15224 100644 --- a/packages/vjudge/src/fetch.ts +++ b/packages/vjudge/src/fetch.ts @@ -44,10 +44,10 @@ export class BasicFetcher { return $dom.window as DOMWindow & { html: string, headers: any }; } - post(url: string) { + post(url: string, type = this.formType) { this.logger.debug('post', url, this.cookie); url = new URL(url, this.endpoint).toString(); - let req = superagent.post(url).set('Cookie', this.cookie).set('User-Agent', this.UA).type(this.formType); + let req = superagent.post(url).set('Cookie', this.cookie).set('User-Agent', this.UA).type(type); if (this.fetchOptions.headers) req = req.set(this.fetchOptions.headers); if (this.fetchOptions.post?.headers) req = req.set(this.fetchOptions.post.headers); return this.account.proxy ? req.proxy(this.account.proxy) : req; diff --git a/packages/vjudge/src/verdict.ts b/packages/vjudge/src/verdict.ts index 15c4cab68..1aeee431f 100644 --- a/packages/vjudge/src/verdict.ts +++ b/packages/vjudge/src/verdict.ts @@ -1,10 +1,15 @@ import { STATUS } from '@hydrooj/common'; export function normalize(key: string) { - return key.toUpperCase().replace(/ /g, '_'); + return key.toUpperCase().replace(/ _-/g, ''); } -export const VERDICT = new Proxy>({ +function removeSlash(src: Record) { + for (const key in Object.keys(src)) src[key.replace(/_/g, '')] = src[key]; + return src; +} + +export const VERDICT = new Proxy>(removeSlash({ RUNTIME_ERROR: STATUS.STATUS_RUNTIME_ERROR, WRONG_ANSWER: STATUS.STATUS_WRONG_ANSWER, OK: STATUS.STATUS_ACCEPTED, @@ -75,7 +80,7 @@ export const VERDICT = new Proxy>({ SYSTEM_ERROR: STATUS.STATUS_SYSTEM_ERROR, SE: STATUS.STATUS_SYSTEM_ERROR, 未知错误: STATUS.STATUS_SYSTEM_ERROR, -}, { +}), { get(self, key) { if (typeof key === 'symbol') return null; key = normalize(key);