From ffe06804a704bde1c87e86eae4931ee5d3c6873f Mon Sep 17 00:00:00 2001 From: Milmon <115549630@qq.com> Date: Tue, 14 May 2024 22:35:34 +0800 Subject: [PATCH] core&ui: add auto organize input option to hack (#780) Co-authored-by: undefined --- packages/hydrooj/locales/en.yaml | 2 ++ packages/hydrooj/locales/zh.yaml | 6 ++++++ packages/hydrooj/src/handler/problem.ts | 11 +++++++++-- packages/hydrooj/src/interface.ts | 4 +++- packages/hydrooj/src/model/record.ts | 4 +++- packages/ui-default/templates/problem_hack.html | 10 ++++++++++ packages/ui-default/templates/record_detail.html | 9 ++++++++- 7 files changed, 41 insertions(+), 5 deletions(-) diff --git a/packages/hydrooj/locales/en.yaml b/packages/hydrooj/locales/en.yaml index 34689b1b6..151c54ba1 100644 --- a/packages/hydrooj/locales/en.yaml +++ b/packages/hydrooj/locales/en.yaml @@ -72,6 +72,7 @@ problem_create: Problem Create problem_detail: Problem Detail problem_edit: Problem Edit problem_files: Problem Files +problem_hack: Hack problem_import: Import Problem problem_main: Problem Set problem_solution: Problem Solution @@ -109,5 +110,6 @@ user_login: Login user_logout: Logout user_lostpass: Lost Password user_register: Register +user_sudo: Entering Sudo Mode wiki_about: About wiki_help: Help \ No newline at end of file diff --git a/packages/hydrooj/locales/zh.yaml b/packages/hydrooj/locales/zh.yaml index 31a12563f..39d5b48e2 100644 --- a/packages/hydrooj/locales/zh.yaml +++ b/packages/hydrooj/locales/zh.yaml @@ -36,6 +36,7 @@ __langname: 简体中文 'The value `{1}` of {0} already exists.': '{0} 的值 `{1}` 已经存在。' 'Yes': 是 "Effects only when Difficulty is not 'Use algorithm calculated'.": 仅当难度不为“使用算法计算”时才起效。 +"Or upload a file:": 或者上传一个文件: "Split by ',' '.'": 由“, ”或“,”分隔。 "What's file?": 什么是文件? (All Problems): (所有题目) @@ -87,7 +88,9 @@ Attend Contest: 参加比赛 Attend contests: 参加比赛 Attended: 已参加 author: 作者 +Auto adjust the format of line breaks and remove unnecessary whitespace characters.: 自动调整换行符格式,并移除不必要的空白字符。 Auto format code: 自动格式化代码 +Auto organize input: 自动整理输入 Avatar: 头像 Back to contest list: 返回比赛列表 Be Copied: 被复制 @@ -281,6 +284,7 @@ Domain: 域 Don't have an account?: 还没有账户? Done: 已结束 Download Dataset: 下载数据集 +Download Hack Input: 下载 Hack 输入 Download link copied to clipboard!: 下载链接已复制到剪贴板。 Download: 下载 Downvote: 差评 @@ -603,6 +607,7 @@ problem_create: 创建题目 problem_detail: 题目详情 problem_edit: 编辑题目 problem_files: 题目文件 +problem_hack: Hack problem_import: 导入题目 problem_main: 题库 problem_solution: 题解 @@ -858,6 +863,7 @@ user_logout: 登出 user_lostpass: 忘记密码 user_register_mail_sent: 注册邮件已发送 user_register: 注册 +user_sudo: 用户安全授权 User-defined role: 用户定义的角色 User: 用户 Username / UID: 用户名或 UID diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 2b0c6b038..fd1dbea31 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -587,8 +587,9 @@ export class ProblemHackHandler extends ProblemDetailHandler { } @param('input', Types.String, true) + @param('autoOrganizeInput', Types.Boolean, true) @param('tid', Types.ObjectId, true) - async post(domainId: string, input = '', tid?: ObjectId) { + async post(domainId: string, input = '', autoOrganizeInput = false, tid?: ObjectId) { await this.limitRate('add_record', 60, system.get('limit.submission_user'), true); await this.limitRate('add_record', 60, system.get('limit.submission'), false); const id = `${this.user._id}/${nanoid()}`; @@ -597,12 +598,18 @@ export class ProblemHackHandler extends ProblemDetailHandler { if (!file || file.size > 128 * 1024 * 1024) throw new ValidationError('input'); await storage.put(`submission/${id}`, file.filepath, this.user._id); } else if (input) { + if (autoOrganizeInput) input = input.replace(/\s+\n/g, '\n').replace(/\s+ /g, ' '); await storage.put(`submission/${id}`, Buffer.from(input), this.user._id); } const rid = await record.add( domainId, this.pdoc.docId, this.user._id, this.rdoc.lang, this.rdoc.code, true, - { contest: tid, type: 'hack', files: { hack: `${id}#input.txt` } }, + { + contest: tid, + type: 'hack', + hackTarget: this.rdoc._id, + files: { hack: `${id}#input.txt` }, + }, ); // TODO contest: update status; this.response.body = { rid }; diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index 83962c39d..aab11e8f3 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -329,8 +329,10 @@ export interface RecordDoc { judgeAt: Date; status: number; progress?: number; - /** pretest & hack */ + /** pretest */ input?: string; + /** hack target rid */ + hackTarget?: ObjectId; /** 0 if pretest&script */ contest?: ObjectId; diff --git a/packages/hydrooj/src/model/record.ts b/packages/hydrooj/src/model/record.ts index e2d1ce4af..472fcf318 100644 --- a/packages/hydrooj/src/model/record.ts +++ b/packages/hydrooj/src/model/record.ts @@ -24,7 +24,7 @@ export default class RecordModel { '_id', 'score', 'time', 'memory', 'lang', 'uid', 'pid', 'rejudged', 'progress', 'domainId', 'contest', 'judger', 'judgeAt', 'status', 'source', - 'files', + 'files', 'hackTarget', ]; static STAT_QUERY = { @@ -122,6 +122,7 @@ export default class RecordModel { contest?: ObjectId, input?: string, files?: Record, + hackTarget?: ObjectId, type: 'judge' | 'rejudge' | 'pretest' | 'hack' | 'generate', } = { type: 'judge' }, ) { @@ -146,6 +147,7 @@ export default class RecordModel { let isContest = !!args.contest; if (args.contest) data.contest = args.contest; if (args.files) data.files = args.files; + if (args.hackTarget) data.hackTarget = args.hackTarget; if (args.type === 'rejudge') { args.type = 'judge'; data.rejudged = true; diff --git a/packages/ui-default/templates/problem_hack.html b/packages/ui-default/templates/problem_hack.html index 65054de93..b8c0ce9ac 100644 --- a/packages/ui-default/templates/problem_hack.html +++ b/packages/ui-default/templates/problem_hack.html @@ -16,6 +16,16 @@
+
+ +
diff --git a/packages/ui-default/templates/record_detail.html b/packages/ui-default/templates/record_detail.html index a71a04cdb..8d629a9c5 100644 --- a/packages/ui-default/templates/record_detail.html +++ b/packages/ui-default/templates/record_detail.html @@ -14,7 +14,10 @@
@@ -63,6 +66,10 @@
{{ _('Submit By') }}
{{ user.render_inline(udoc, modbadge=false) }}
+ {% if rdoc.hackTarget %} +
{{ _('Hacked') }}
+
{{ rdoc.hackTarget }}
+ {% endif %} {% if pdoc %}
{{ _('Problem') }}