mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09:38:19 +08:00
Merge branch 'master' into contest-problemlist
This commit is contained in:
commit
58c0cade0e
28 files changed
+304
-187
No files matched your search
@@ -17,9 +17,9 @@ import message from '../model/message';
|
||||
import * as oplog from '../model/oplog';
|
||||
import problem from '../model/problem';
|
||||
import record from '../model/record';
|
||||
import ScheduleModel from '../model/schedule';
|
||||
import storage from '../model/storage';
|
||||
import * as system from '../model/system';
|
||||
import TaskModel from '../model/task';
|
||||
import user from '../model/user';
|
||||
import {
|
||||
Handler, param, post, Types,
|
||||
@@ -52,7 +52,7 @@ registerResolver(
|
||||
'Get a contest by ID',
|
||||
);
|
||||
|
||||
TaskModel.Worker.addHandler('contest', async (doc) => {
|
||||
ScheduleModel.Worker.addHandler('contest', async (doc) => {
|
||||
const tdoc = await contest.get(doc.domainId, doc.tid);
|
||||
if (!tdoc) return;
|
||||
const tasks = [];
|
||||
@@ -199,7 +199,7 @@ export class ContestDetailHandler extends ContestDetailBaseHandler {
|
||||
if (!this.user.own(this.tdoc)) this.checkPerm(PERM.PERM_EDIT_CONTEST);
|
||||
await contest.del(domainId, tid);
|
||||
await record.updateMulti(domainId, { domainId, contest: tid }, undefined, undefined, { contest: '' });
|
||||
await TaskModel.deleteMany({
|
||||
await ScheduleModel.deleteMany({
|
||||
type: 'schedule', subType: 'contest', domainId, tid,
|
||||
});
|
||||
this.response.redirect = this.url('contest_main');
|
||||
@@ -346,20 +346,18 @@ export class ContestEditHandler extends Handler {
|
||||
const task = {
|
||||
type: 'schedule', subType: 'contest', domainId, tid,
|
||||
};
|
||||
await TaskModel.deleteMany(task);
|
||||
await ScheduleModel.deleteMany(task);
|
||||
const operation = [];
|
||||
if (Date.now() <= endAt.getTime() && autoHide) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Promise.all(pids.map((pid) => problem.edit(domainId, pid, { hidden: true })));
|
||||
await TaskModel.add({
|
||||
...task,
|
||||
operation: ['unhide'],
|
||||
executeAfter: endAt,
|
||||
});
|
||||
operation.push('unhide');
|
||||
}
|
||||
if (lock && lockAt <= endAt) {
|
||||
await TaskModel.add({
|
||||
if (lock && lockAt <= endAt) operation.push('unlock');
|
||||
if (operation.length) {
|
||||
await ScheduleModel.add({
|
||||
...task,
|
||||
operation: ['unlock'],
|
||||
operation,
|
||||
executeAfter: endAt,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,9 +103,7 @@ export async function postJudge(rdoc: RecordDoc) {
|
||||
contest: { $ne: new ObjectID('0'.repeat(24)) },
|
||||
}).project({ _id: 1, contest: 1 }).toArray();
|
||||
const priority = await record.submissionPriority(rdoc.uid, -5000 - rdocs.length * 5 - 50);
|
||||
await Promise.all(rdocs.map(
|
||||
(r) => record.judge(rdoc.domainId, r._id, priority, r.contest ? { detail: false } : {}, { hackRejudge: input }),
|
||||
));
|
||||
await record.judge(rdoc.domainId, rdocs.map((r) => r._id), priority, {}, { hackRejudge: input });
|
||||
} catch (e) {
|
||||
next({
|
||||
rid: rdoc._id, domainId: rdoc.domainId, key: 'next', message: { message: 'Unable to apply hack: {0}', params: [e.message] },
|
||||
@@ -202,10 +200,11 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
if (!t) await sleep(500);
|
||||
}
|
||||
this.send({ task: t });
|
||||
let rdoc = await record.get(t.domainId, t.rid);
|
||||
this.send({ task: { ...rdoc, ...t } });
|
||||
this.processing = t;
|
||||
const $set = { status: builtin.STATUS.STATUS_FETCHED };
|
||||
const rdoc = await record.update(t.domainId, t.rid, $set, {});
|
||||
rdoc = await record.update(t.domainId, t.rid, $set, {});
|
||||
bus.broadcast('record/change', rdoc, $set, {});
|
||||
}
|
||||
|
||||
|
||||
@@ -286,10 +286,11 @@ class SystemUserPrivHandler extends SystemHandler {
|
||||
}
|
||||
|
||||
@requireSudo
|
||||
@param('uid', Types.Int, true)
|
||||
@param('uid', Types.Int)
|
||||
@param('priv', Types.UnsignedInt)
|
||||
async post(domainId: string, uid: number, priv: number) {
|
||||
if (typeof uid === 'number') {
|
||||
@param('system', Types.Boolean, true)
|
||||
async post(domainId: string, uid: number, priv: number, editSystem: boolean) {
|
||||
if (!editSystem) {
|
||||
const udoc = await user.getById(domainId, uid);
|
||||
if (!udoc) throw new UserNotFoundError(uid);
|
||||
if (udoc.priv === -1 || priv === -1 || priv === allPriv) throw new ForbiddenError('you can not edit user as SU in web.');
|
||||
|
||||
@@ -443,17 +443,17 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
|
||||
@param('pid', Types.UnsignedInt)
|
||||
async postRejudge(domainId: string, pid: number) {
|
||||
this.checkPerm(PERM.PERM_REJUDGE_PROBLEM);
|
||||
// TODO maybe async?
|
||||
const rdocs = await record.getMulti(domainId, {
|
||||
pid,
|
||||
contest: { $ne: new ObjectID('0'.repeat(24)) },
|
||||
'files.hack': { $exists: false },
|
||||
}).project({ _id: 1, contest: 1 }).toArray();
|
||||
const priority = await record.submissionPriority(this.user._id, -10000 - rdocs.length * 5 - 50);
|
||||
await Promise.all(rdocs.map(
|
||||
(doc) => record.reset(domainId, doc._id, true)
|
||||
.then(() => record.judge(domainId, doc._id, priority, doc.contest ? { detail: false } : {})),
|
||||
));
|
||||
await record.reset(domainId, rdocs.map((rdoc) => rdoc._id), true);
|
||||
await Promise.all([
|
||||
record.judge(domainId, rdocs.filter((i) => i.contest).map((i) => i._id), priority, { detail: false }),
|
||||
record.judge(domainId, rdocs.filter((i) => !i.contest).map((i) => i._id), priority, {}),
|
||||
]);
|
||||
this.back();
|
||||
}
|
||||
|
||||
|
||||
@@ -100,10 +100,7 @@ class RecordListHandler extends ContestDetailBaseHandler {
|
||||
filterStatus: status,
|
||||
};
|
||||
if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS) && !full) {
|
||||
this.response.body.statistics = {
|
||||
...await record.stat(all ? undefined : domainId),
|
||||
delay: await TaskModel.getDelay({ type: 'judge' }),
|
||||
};
|
||||
this.response.body.statistics = await record.stat(all ? undefined : domainId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ import domain from '../model/domain';
|
||||
import oauth from '../model/oauth';
|
||||
import * as oplog from '../model/oplog';
|
||||
import problem, { ProblemDoc } from '../model/problem';
|
||||
import ScheduleModel from '../model/schedule';
|
||||
import SolutionModel from '../model/solution';
|
||||
import * as system from '../model/system';
|
||||
import task from '../model/task';
|
||||
import token from '../model/token';
|
||||
import user from '../model/user';
|
||||
import {
|
||||
@@ -376,7 +376,7 @@ class UserDetailHandler extends Handler {
|
||||
class UserDeleteHandler extends Handler {
|
||||
async post({ password }) {
|
||||
this.user.checkPassword(password);
|
||||
const tid = await task.add({
|
||||
const tid = await ScheduleModel.add({
|
||||
executeAfter: moment().add(7, 'days').toDate(),
|
||||
type: 'script',
|
||||
id: 'deleteUser',
|
||||
|
||||
Reference in new issue
Block a user