mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 17:38:19 +08:00
core&ui: fix remote_judge for cors problem
This commit is contained in:
1 parent
21d18780e4
commit
6905b9953e
5 files changed
+54
-24
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.33.8",
|
||||
"version": "2.33.9",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -3,12 +3,15 @@ import { ObjectID } from 'mongodb';
|
||||
import AdmZip from 'adm-zip';
|
||||
import { Time } from '@hydrooj/utils/lib/utils';
|
||||
import { lookup } from 'mime-types';
|
||||
import { intersection } from 'lodash';
|
||||
import {
|
||||
ContestNotLiveError, ValidationError, ProblemNotFoundError,
|
||||
ContestNotAttendedError, PermissionError, BadRequestError,
|
||||
ContestNotFoundError, InvalidTokenError, RecordNotFoundError,
|
||||
} from '../error';
|
||||
import { ProblemDoc, Tdoc, User } from '../interface';
|
||||
import {
|
||||
ProblemDoc, Tdoc, User, DomainDoc,
|
||||
} from '../interface';
|
||||
import paginate from '../lib/paginate';
|
||||
import { PERM, PRIV } from '../model/builtin';
|
||||
import * as contest from '../model/contest';
|
||||
@@ -341,8 +344,25 @@ export class ContestProblemFileDownloadHandler 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);
|
||||
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)
|
||||
@@ -367,24 +387,20 @@ export class ContestDetailProblemSubmitHandler extends ContestProblemHandler {
|
||||
@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];
|
||||
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.');
|
||||
}
|
||||
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'));
|
||||
const rid = await record.add(domainId, pid, this.user._id, lang, code, true, pretest ? input : {
|
||||
type: document.TYPE_CONTEST,
|
||||
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);
|
||||
if (!rdoc) throw new RecordNotFoundError(domainId, rid);
|
||||
if (!pretest) {
|
||||
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'),
|
||||
contest.updateStatus(domainId, tid, this.user._id, rid, pid),
|
||||
]);
|
||||
|
||||
@@ -4,12 +4,13 @@ import { ObjectID } from 'mongodb';
|
||||
import AdmZip from 'adm-zip';
|
||||
import { Time } from '@hydrooj/utils/lib/utils';
|
||||
import { lookup } from 'mime-types';
|
||||
import { intersection } from 'lodash';
|
||||
import {
|
||||
ValidationError, HomeworkNotLiveError, ProblemNotFoundError,
|
||||
HomeworkNotAttendedError, BadRequestError,
|
||||
} from '../error';
|
||||
import {
|
||||
PenaltyRules, Tdoc, ProblemDoc, User,
|
||||
PenaltyRules, Tdoc, ProblemDoc, User, DomainDoc,
|
||||
} from '../interface';
|
||||
import {
|
||||
Route, Handler, Types, param,
|
||||
@@ -206,10 +207,26 @@ export class HomeworkProblemFileDownloadHandler extends HomeworkDetailProblemHan
|
||||
}
|
||||
|
||||
class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
|
||||
pdomainId: string;
|
||||
ppid: number;
|
||||
pdomain: DomainDoc;
|
||||
|
||||
@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 (!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)
|
||||
@@ -236,20 +253,16 @@ class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
|
||||
if (this.response.body.pdoc.config?.langs && !this.response.body.pdoc.config.langs.includes(lang)) {
|
||||
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'));
|
||||
const rid = await record.add(domainId, pid, this.user._id, lang, code, true, pretest ? input : {
|
||||
type: document.TYPE_HOMEWORK,
|
||||
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);
|
||||
if (pretest) {
|
||||
if (!pretest) {
|
||||
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'),
|
||||
contest.updateStatus(domainId, tid, this.user._id,
|
||||
rid, pid, false, 0, document.TYPE_HOMEWORK),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.18.5",
|
||||
"version": "4.18.6",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
@@ -12,12 +12,14 @@ const page = new NamedPage(['problem_submit', 'contest_detail_problem_submit', '
|
||||
$(ev.currentTarget).hide();
|
||||
$('[name="problem-sidebar__categories"]').show();
|
||||
});
|
||||
|
||||
const { domainId } = UiContext.pdocConfig;
|
||||
|
||||
function onChangeMain(update = true) {
|
||||
const options = {};
|
||||
for (const key in window.LANGS) {
|
||||
if (UiContext.pdocConfig.langs && !UiContext.pdocConfig.langs.includes(key)) continue;
|
||||
if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(UiContext.domainId)) continue;
|
||||
if (UiContext.domain.langs && !`,${UiContext.domain.langs},`.includes(`,${key},`)) continue;
|
||||
if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(domainId)) continue;
|
||||
if (key.startsWith(`${this.value}.`) && key !== this.value) options[key] = window.LANGS[key].display;
|
||||
}
|
||||
setOptions($('#codelang-sub-select'), options);
|
||||
@@ -33,8 +35,7 @@ const page = new NamedPage(['problem_submit', 'contest_detail_problem_submit', '
|
||||
const main = {};
|
||||
for (const key in window.LANGS) {
|
||||
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 (UiContext.domain.langs && !`,${UiContext.domain.langs},`.includes(`,${key},`)) continue;
|
||||
if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(domainId)) continue;
|
||||
if (!key.includes('.')) main[key] = window.LANGS[key].display;
|
||||
}
|
||||
setOptions($('#codelang-main-select'), main);
|
||||
|
||||
Reference in new issue
Block a user