From 050b4995ee43eca54013a9e76d2348e02e17d2c4 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Feb 2023 11:44:18 +0800 Subject: [PATCH] feat(remote_judger/loj): include source code in result when fetching from archive --- remote_judger/src/interface.ts | 3 ++- remote_judger/src/providers/loj.ts | 21 +++++++++++++++++++-- remote_judger/src/vjudge.ts | 3 ++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/remote_judger/src/interface.ts b/remote_judger/src/interface.ts index d26ced1..3b8f1b6 100644 --- a/remote_judger/src/interface.ts +++ b/remote_judger/src/interface.ts @@ -23,7 +23,8 @@ export interface IBasicProvider { id: string, next: NextFunction, end: NextFunction, - problem_id?: string + problem_id: string, + result_show_source?: boolean ): Promise; } diff --git a/remote_judger/src/providers/loj.ts b/remote_judger/src/providers/loj.ts index 261f623..f8b9ca4 100644 --- a/remote_judger/src/providers/loj.ts +++ b/remote_judger/src/providers/loj.ts @@ -1,11 +1,12 @@ import superagent from 'superagent'; import proxy from 'superagent-proxy'; import { stripVTControlCharacters } from 'util'; +import { crlf, LF } from 'crlf-normalize'; import sleep from '../utils/sleep'; import { IBasicProvider, RemoteAccount, USER_AGENT } from '../interface'; import Logger from '../utils/logger'; import { normalize, VERDICT } from '../verdict'; -import { crlf, LF } from 'crlf-normalize'; +import htmlspecialchars from '../utils/htmlspecialchars'; proxy(superagent); const logger = new Logger('remote/loj'); @@ -285,7 +286,13 @@ export default class LibreojProvider implements IBasicProvider { return user_id === submission_user_id; } - async waitForSubmission(id: string, next, end, problem_id: string) { + async waitForSubmission( + id: string, + next, + end, + problem_id: string, + result_show_source = false + ) { if (!(await this.ensureLogin())) { await end({ error: true, @@ -463,6 +470,16 @@ export default class LibreojProvider implements IBasicProvider { `

Verdict: ${status}

` + ''; + if (result_show_source) { + details += + '
' + + '
源代码
' + + `
` +
+            htmlspecialchars(parse(body.content.code)) +
+            '
' + + '
'; + } + // Samples if (body.progress.samples) { details += `