mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix pretest
This commit is contained in:
1 parent
b6441b853b
commit
8a647dc36a
7 files changed
+30
-23
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.28.14",
|
"version": "2.28.15",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -343,24 +343,26 @@ export class ContestDetailProblemSubmitHandler extends ContestProblemHandler {
|
|||||||
@param('lang', Types.Name)
|
@param('lang', Types.Name)
|
||||||
@param('code', Types.Content)
|
@param('code', Types.Content)
|
||||||
@param('pid', Types.Name)
|
@param('pid', Types.Name)
|
||||||
async post(domainId: string, tid: ObjectID, lang: string, code: string, _pid: string) {
|
@param('pretest', Types.Boolean)
|
||||||
|
@param('input', Types.String, true)
|
||||||
|
async post(domainId: string, tid: ObjectID, lang: string, code: string, _pid: string, pretest = false, input = '') {
|
||||||
const pid = this.tdoc.pids[parseInt(_pid, 36) - 10];
|
const pid = this.tdoc.pids[parseInt(_pid, 36) - 10];
|
||||||
if (this.response.body.pdoc.config?.langs && !this.response.body.pdoc.config.langs.includes(lang)) {
|
if (this.response.body.pdoc.config?.langs && !this.response.body.pdoc.config.langs.includes(lang)) {
|
||||||
throw new BadRequestError('Language not allowed.');
|
throw new BadRequestError('Language not allowed.');
|
||||||
}
|
}
|
||||||
await this.limitRate('add_record', 60, 10);
|
await this.limitRate('add_record', 60, 10);
|
||||||
const rid = await record.add(domainId, pid, this.user._id, lang, code, true, {
|
const rid = await record.add(domainId, pid, this.user._id, lang, code, true, pretest ? input : {
|
||||||
type: document.TYPE_CONTEST,
|
type: document.TYPE_CONTEST,
|
||||||
tid,
|
tid,
|
||||||
});
|
});
|
||||||
const [rdoc] = await Promise.all([
|
const rdoc = await record.get(domainId, rid);
|
||||||
record.get(domainId, rid),
|
await Promise.all([
|
||||||
problem.inc(domainId, pid, 'nSubmit', 1),
|
problem.inc(domainId, pid, 'nSubmit', 1),
|
||||||
domain.incUserInDomain(domainId, this.user._id, 'nSubmit'),
|
domain.incUserInDomain(domainId, this.user._id, 'nSubmit'),
|
||||||
contest.updateStatus(domainId, tid, this.user._id, rid, pid),
|
contest.updateStatus(domainId, tid, this.user._id, rid, pid),
|
||||||
]);
|
]);
|
||||||
bus.boardcast('record/change', rdoc);
|
bus.boardcast('record/change', rdoc);
|
||||||
if (!contest.canShowRecord.call(this, this.tdoc)) {
|
if (!pretest && !contest.canShowRecord.call(this, this.tdoc)) {
|
||||||
this.response.body = { tid };
|
this.response.body = { tid };
|
||||||
this.response.redirect = this.url('contest_detail', { tid });
|
this.response.redirect = this.url('contest_detail', { tid });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -217,20 +217,22 @@ class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
|
|||||||
@param('pid', Types.String)
|
@param('pid', Types.String)
|
||||||
@param('code', Types.Content)
|
@param('code', Types.Content)
|
||||||
@param('lang', Types.Name)
|
@param('lang', Types.Name)
|
||||||
async post(domainId: string, tid: ObjectID, _pid: string, code: string, lang: string) {
|
@param('pretest', Types.Boolean)
|
||||||
|
@param('input', Types.String, true)
|
||||||
|
async post(domainId: string, tid: ObjectID, _pid: string, code: string, lang: string, pretest = false, input = '') {
|
||||||
const pid = this.tdoc.pids[parseInt(_pid, 36) - 10];
|
const pid = this.tdoc.pids[parseInt(_pid, 36) - 10];
|
||||||
if (this.response.body.pdoc.config?.langs && !this.response.body.pdoc.config.langs.includes(lang)) {
|
if (this.response.body.pdoc.config?.langs && !this.response.body.pdoc.config.langs.includes(lang)) {
|
||||||
throw new BadRequestError('Language not allowed.');
|
throw new BadRequestError('Language not allowed.');
|
||||||
}
|
}
|
||||||
await this.limitRate('add_record', 60, 5);
|
await this.limitRate('add_record', 60, 5);
|
||||||
const rid = await record.add(domainId, pid, this.user._id, lang, code, true, {
|
const rid = await record.add(domainId, pid, this.user._id, lang, code, true, pretest ? input : {
|
||||||
type: document.TYPE_HOMEWORK,
|
type: document.TYPE_HOMEWORK,
|
||||||
tid,
|
tid,
|
||||||
});
|
});
|
||||||
const pdomainId = typeof pid === 'string' ? pid.split(':')[0] : domainId;
|
const pdomainId = typeof pid === 'string' ? pid.split(':')[0] : domainId;
|
||||||
const ppid = typeof pid === 'number' ? pid : +pid.split(':')[1];
|
const ppid = typeof pid === 'number' ? pid : +pid.split(':')[1];
|
||||||
const [rdoc] = await Promise.all([
|
const rdoc = await record.get(domainId, rid);
|
||||||
record.get(domainId, rid),
|
await Promise.all([
|
||||||
problem.inc(pdomainId, ppid, 'nSubmit', 1),
|
problem.inc(pdomainId, ppid, 'nSubmit', 1),
|
||||||
domain.incUserInDomain(domainId, this.user._id, 'nSubmit'),
|
domain.incUserInDomain(domainId, this.user._id, 'nSubmit'),
|
||||||
contest.updateStatus(domainId, tid, this.user._id,
|
contest.updateStatus(domainId, tid, this.user._id,
|
||||||
@@ -239,7 +241,7 @@ class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
|
|||||||
bus.boardcast('record/change', rdoc);
|
bus.boardcast('record/change', rdoc);
|
||||||
this.response.body.tid = tid;
|
this.response.body.tid = tid;
|
||||||
this.response.body.rid = rid;
|
this.response.body.rid = rid;
|
||||||
if (contest.canShowRecord.call(this, this.tdoc)) this.response.redirect = this.url('record_detail', { rid });
|
if (pretest || contest.canShowRecord.call(this, this.tdoc)) this.response.redirect = this.url('record_detail', { rid });
|
||||||
else this.response.redirect = this.url('homework_detail', { tid });
|
else this.response.redirect = this.url('homework_detail', { tid });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,18 +267,22 @@ export class ProblemSubmitHandler extends ProblemDetailHandler {
|
|||||||
|
|
||||||
@param('lang', Types.Name)
|
@param('lang', Types.Name)
|
||||||
@param('code', Types.Content)
|
@param('code', Types.Content)
|
||||||
async post(domainId: string, lang: string, code: string) {
|
@param('pretest', Types.Boolean)
|
||||||
|
@param('input', Types.String, true)
|
||||||
|
async post(domainId: string, lang: string, code: string, pretest = false, input = '') {
|
||||||
if (this.response.body.pdoc.config?.langs && !this.response.body.pdoc.config.langs.includes(lang)) {
|
if (this.response.body.pdoc.config?.langs && !this.response.body.pdoc.config.langs.includes(lang)) {
|
||||||
throw new BadRequestError('Language not allowed.');
|
throw new BadRequestError('Language not allowed.');
|
||||||
}
|
}
|
||||||
await this.limitRate('add_record', 60, 5);
|
await this.limitRate('add_record', 60, 5);
|
||||||
const rid = await record.add(domainId, this.pdoc.docId, this.user._id, lang, code, true);
|
const rid = await record.add(domainId, this.pdoc.docId, this.user._id, lang, code, true, pretest ? input : undefined);
|
||||||
const [rdoc] = await Promise.all([
|
const rdoc = await record.get(domainId, rid);
|
||||||
record.get(domainId, rid),
|
if (!pretest) {
|
||||||
problem.inc(domainId, this.pdoc.docId, 'nSubmit', 1),
|
await Promise.all([
|
||||||
problem.incStatus(domainId, this.pdoc.docId, this.user._id, 'nSubmit', 1),
|
problem.inc(domainId, this.pdoc.docId, 'nSubmit', 1),
|
||||||
domain.incUserInDomain(domainId, this.user._id, 'nSubmit'),
|
problem.incStatus(domainId, this.pdoc.docId, this.user._id, 'nSubmit', 1),
|
||||||
]);
|
domain.incUserInDomain(domainId, this.user._id, 'nSubmit'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
bus.boardcast('record/change', rdoc);
|
bus.boardcast('record/change', rdoc);
|
||||||
this.response.body = { rid };
|
this.response.body = { rid };
|
||||||
this.response.redirect = this.url('record_detail', { rid });
|
this.response.redirect = this.url('record_detail', { rid });
|
||||||
@@ -613,7 +617,6 @@ export async function apply() {
|
|||||||
Route('problem_random', '/problem/random', ProblemRandomHandler, PERM.PERM_VIEW_PROBLEM);
|
Route('problem_random', '/problem/random', ProblemRandomHandler, PERM.PERM_VIEW_PROBLEM);
|
||||||
Route('problem_detail', '/p/:pid', ProblemDetailHandler, PERM.PERM_VIEW_PROBLEM);
|
Route('problem_detail', '/p/:pid', ProblemDetailHandler, PERM.PERM_VIEW_PROBLEM);
|
||||||
Route('problem_submit', '/p/:pid/submit', ProblemSubmitHandler, PERM.PERM_SUBMIT_PROBLEM);
|
Route('problem_submit', '/p/:pid/submit', ProblemSubmitHandler, PERM.PERM_SUBMIT_PROBLEM);
|
||||||
Route('problem_pretest', '/p/:pid/pretest', ProblemPretestHandler, PERM.PERM_SUBMIT_PROBLEM);
|
|
||||||
Route('problem_edit', '/p/:pid/edit', ProblemEditHandler);
|
Route('problem_edit', '/p/:pid/edit', ProblemEditHandler);
|
||||||
Route('problem_files', '/p/:pid/files', ProblemFilesHandler, PERM.PERM_VIEW_PROBLEM);
|
Route('problem_files', '/p/:pid/files', ProblemFilesHandler, PERM.PERM_VIEW_PROBLEM);
|
||||||
Route('problem_file_download', '/p/:pid/file/:filename', ProblemFileDownloadHandler, PERM.PERM_VIEW_PROBLEM);
|
Route('problem_file_download', '/p/:pid/file/:filename', ProblemFileDownloadHandler, PERM.PERM_VIEW_PROBLEM);
|
||||||
|
|||||||
@@ -37,10 +37,11 @@ const mapDispatchToProps = (dispatch) => ({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
postPretest(props) {
|
postPretest(props) {
|
||||||
const req = request.post(UiContext.postPretestUrl, {
|
const req = request.post(UiContext.postSubmitUrl, {
|
||||||
lang: props.editorLang,
|
lang: props.editorLang,
|
||||||
code: props.editorCode,
|
code: props.editorCode,
|
||||||
input: props.pretestInput || ' ',
|
input: props.pretestInput || ' ',
|
||||||
|
pretest: true,
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'SCRATCHPAD_POST_PRETEST',
|
type: 'SCRATCHPAD_POST_PRETEST',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.11.6",
|
"version": "4.11.7",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
{{ set(UiContext, {
|
{{ set(UiContext, {
|
||||||
problemId: pdoc.pid|default(pdoc.docId),
|
problemId: pdoc.pid|default(pdoc.docId),
|
||||||
problemNumId: pdoc.docId,
|
problemNumId: pdoc.docId,
|
||||||
postPretestUrl: url('problem_pretest', pid=pdoc.docId),
|
|
||||||
codeLang: handler.user.codeLang,
|
codeLang: handler.user.codeLang,
|
||||||
codeTemplate: handler.user.codeTemplate,
|
codeTemplate: handler.user.codeTemplate,
|
||||||
pdoc: pdoc
|
pdoc: pdoc
|
||||||
|
|||||||
Reference in new issue
Block a user