core&ui: fix remote_judge for cors problem

This commit is contained in:
undefined committed 2021-08-26 01:11:50 +08:00
1 parent 21d18780e4
commit 6905b9953e
5 files changed
+54 -24

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.33.8", "version": "2.33.9",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",
+25 -9
View File
@@ -3,12 +3,15 @@ import { ObjectID } from 'mongodb';
import AdmZip from 'adm-zip'; import AdmZip from 'adm-zip';
import { Time } from '@hydrooj/utils/lib/utils'; import { Time } from '@hydrooj/utils/lib/utils';
import { lookup } from 'mime-types'; import { lookup } from 'mime-types';
import { intersection } from 'lodash';
import { import {
ContestNotLiveError, ValidationError, ProblemNotFoundError, ContestNotLiveError, ValidationError, ProblemNotFoundError,
ContestNotAttendedError, PermissionError, BadRequestError, ContestNotAttendedError, PermissionError, BadRequestError,
ContestNotFoundError, InvalidTokenError, RecordNotFoundError, ContestNotFoundError, InvalidTokenError, RecordNotFoundError,
} from '../error'; } from '../error';
import { ProblemDoc, Tdoc, User } from '../interface'; import {
ProblemDoc, Tdoc, User, DomainDoc,
} from '../interface';
import paginate from '../lib/paginate'; import paginate from '../lib/paginate';
import { PERM, PRIV } from '../model/builtin'; import { PERM, PRIV } from '../model/builtin';
import * as contest from '../model/contest'; import * as contest from '../model/contest';
@@ -341,8 +344,25 @@ export class ContestProblemFileDownloadHandler extends ContestProblemHandler {
} }
export class ContestDetailProblemSubmitHandler extends ContestProblemHandler { export class ContestDetailProblemSubmitHandler extends ContestProblemHandler {
async prepare() { pdomainId: string;
ppid: number;
pdomain: DomainDoc;
@param('pid', Types.Name)
async prepare(domainId: string, _pid: string) {
const pid = this.tdoc.pids[parseInt(_pid, 36) - 10];
if (!this.attended) throw new ContestNotAttendedError(this.tdoc.docId);
if (!contest.isOngoing(this.tdoc)) throw new ContestNotLiveError(this.tdoc.docId); if (!contest.isOngoing(this.tdoc)) throw new ContestNotLiveError(this.tdoc.docId);
this.pdomainId = typeof pid === 'string' ? pid.split(':')[0] : domainId;
this.ppid = typeof pid === 'number' ? pid : +pid.split(':')[1];
this.pdomain = await domain.get(this.pdomainId);
if (this.pdomain.langs) {
this.response.body.pdoc.config.langs = intersection(
this.response.body.pdoc.config.langs || this.pdomain.langs.split(','),
this.pdomain.langs.split(','),
);
}
this.response.body.pdoc.config.domainId = this.pdomainId;
} }
@param('tid', Types.ObjectID) @param('tid', Types.ObjectID)
@@ -367,24 +387,20 @@ export class ContestDetailProblemSubmitHandler extends ContestProblemHandler {
@param('input', Types.String, true) @param('input', Types.String, true)
async post(domainId: string, tid: ObjectID, lang: string, code: string, _pid: string, pretest = false, input = '') { 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 || [lang]).includes(lang)) {
throw new BadRequestError('Language not allowed.'); throw new BadRequestError('Language not allowed.');
} }
if (this.domain.langs && !this.domain.langs.includes(lang)) {
throw new BadRequestError('Language not allowed');
}
await this.limitRate('add_record', 60, system.get('limit.submission')); await this.limitRate('add_record', 60, system.get('limit.submission'));
const rid = await record.add(domainId, pid, this.user._id, lang, code, true, pretest ? input : { 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 pdomainId = typeof pid === 'string' ? pid.split(':')[0] : domainId;
const ppid = typeof pid === 'number' ? pid : +pid.split(':')[1];
const rdoc = await record.get(domainId, rid); const rdoc = await record.get(domainId, rid);
if (!rdoc) throw new RecordNotFoundError(domainId, rid); if (!rdoc) throw new RecordNotFoundError(domainId, rid);
if (!pretest) { if (!pretest) {
await Promise.all([ await Promise.all([
(this.tsdoc.journal || []).filter((i) => i.pid === pid).length ? Promise.resolve() : problem.inc(pdomainId, ppid, 'nSubmit', 1), (this.tsdoc.journal || []).filter((i) => i.pid === pid).length
&& problem.inc(this.pdomainId, this.ppid, '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),
]); ]);
+22 -9
View File
@@ -4,12 +4,13 @@ import { ObjectID } from 'mongodb';
import AdmZip from 'adm-zip'; import AdmZip from 'adm-zip';
import { Time } from '@hydrooj/utils/lib/utils'; import { Time } from '@hydrooj/utils/lib/utils';
import { lookup } from 'mime-types'; import { lookup } from 'mime-types';
import { intersection } from 'lodash';
import { import {
ValidationError, HomeworkNotLiveError, ProblemNotFoundError, ValidationError, HomeworkNotLiveError, ProblemNotFoundError,
HomeworkNotAttendedError, BadRequestError, HomeworkNotAttendedError, BadRequestError,
} from '../error'; } from '../error';
import { import {
PenaltyRules, Tdoc, ProblemDoc, User, PenaltyRules, Tdoc, ProblemDoc, User, DomainDoc,
} from '../interface'; } from '../interface';
import { import {
Route, Handler, Types, param, Route, Handler, Types, param,
@@ -206,10 +207,26 @@ export class HomeworkProblemFileDownloadHandler extends HomeworkDetailProblemHan
} }
class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler { class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
pdomainId: string;
ppid: number;
pdomain: DomainDoc;
@param('tid', Types.ObjectID) @param('tid', Types.ObjectID)
async prepare(domainId: string, tid: ObjectID) { @param('pid', Types.Name)
async prepare(domainId: string, tid: ObjectID, _pid: string) {
const pid = this.tdoc.pids[parseInt(_pid, 36) - 10];
if (!this.attended) throw new HomeworkNotAttendedError(tid); if (!this.attended) throw new HomeworkNotAttendedError(tid);
if (!contest.isOngoing(this.tdoc)) throw new HomeworkNotLiveError(tid); if (!contest.isOngoing(this.tdoc)) throw new HomeworkNotLiveError(tid);
this.pdomainId = typeof pid === 'string' ? pid.split(':')[0] : domainId;
this.ppid = typeof pid === 'number' ? pid : +pid.split(':')[1];
this.pdomain = await domain.get(this.pdomainId);
if (this.pdomain.langs) {
this.response.body.pdoc.config.langs = intersection(
this.response.body.pdoc.config.langs || this.pdomain.langs.split(','),
this.pdomain.langs.split(','),
);
}
this.response.body.pdoc.config.domainId = this.pdomainId;
} }
@param('tid', Types.ObjectID) @param('tid', Types.ObjectID)
@@ -236,20 +253,16 @@ class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
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.');
} }
if (this.domain.langs && !this.domain.langs.includes(lang)) {
throw new BadRequestError('Language not allowed');
}
await this.limitRate('add_record', 60, system.get('limit.submission')); await this.limitRate('add_record', 60, system.get('limit.submission'));
const rid = await record.add(domainId, pid, this.user._id, lang, code, true, pretest ? input : { 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 ppid = typeof pid === 'number' ? pid : +pid.split(':')[1];
const rdoc = await record.get(domainId, rid); const rdoc = await record.get(domainId, rid);
if (pretest) { if (!pretest) {
await Promise.all([ await Promise.all([
(this.tsdoc.journal || []).filter((i) => i.pid === pid).length ? Promise.resolve() : problem.inc(pdomainId, ppid, 'nSubmit', 1), (this.tsdoc.journal || []).filter((i) => i.pid === pid).length
&& problem.inc(this.pdomainId, this.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,
rid, pid, false, 0, document.TYPE_HOMEWORK), rid, pid, false, 0, document.TYPE_HOMEWORK),
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.18.5", "version": "4.18.6",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",
@@ -12,12 +12,14 @@ const page = new NamedPage(['problem_submit', 'contest_detail_problem_submit', '
$(ev.currentTarget).hide(); $(ev.currentTarget).hide();
$('[name="problem-sidebar__categories"]').show(); $('[name="problem-sidebar__categories"]').show();
}); });
const { domainId } = UiContext.pdocConfig;
function onChangeMain(update = true) { function onChangeMain(update = true) {
const options = {}; const options = {};
for (const key in window.LANGS) { for (const key in window.LANGS) {
if (UiContext.pdocConfig.langs && !UiContext.pdocConfig.langs.includes(key)) continue; if (UiContext.pdocConfig.langs && !UiContext.pdocConfig.langs.includes(key)) continue;
if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(UiContext.domainId)) continue; if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(domainId)) continue;
if (UiContext.domain.langs && !`,${UiContext.domain.langs},`.includes(`,${key},`)) continue;
if (key.startsWith(`${this.value}.`) && key !== this.value) options[key] = window.LANGS[key].display; if (key.startsWith(`${this.value}.`) && key !== this.value) options[key] = window.LANGS[key].display;
} }
setOptions($('#codelang-sub-select'), options); setOptions($('#codelang-sub-select'), options);
@@ -33,8 +35,7 @@ const page = new NamedPage(['problem_submit', 'contest_detail_problem_submit', '
const main = {}; const main = {};
for (const key in window.LANGS) { for (const key in window.LANGS) {
if (UiContext.pdocConfig.langs && !UiContext.pdocConfig.langs.filter((i) => i === key || i.startsWith(`${key}.`)).length) continue; if (UiContext.pdocConfig.langs && !UiContext.pdocConfig.langs.filter((i) => i === key || i.startsWith(`${key}.`)).length) continue;
if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(UiContext.domainId)) continue; if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(domainId)) continue;
if (UiContext.domain.langs && !`,${UiContext.domain.langs},`.includes(`,${key},`)) continue;
if (!key.includes('.')) main[key] = window.LANGS[key].display; if (!key.includes('.')) main[key] = window.LANGS[key].display;
} }
setOptions($('#codelang-main-select'), main); setOptions($('#codelang-main-select'), main);