mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: add auto organize input option to hack (#780)
Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
1 parent
42569783f9
commit
ffe06804a7
7 files changed
+41
-5
No files matched your search
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<string, string>,
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user