core&ui: bug fix

This commit is contained in:
undefined committed 2021-05-30 18:42:49 +08:00
1 parent 8532cb5ec3
commit 3a518010be
13 files changed
+27 -30

No files matched your search

+1 -1
View File
@@ -220,7 +220,7 @@ export class ContestEditHandler extends Handler {
) {
const pids = _pids.replace(/,/g, ',').split(',').map((i) => {
if ((+i).toString() === i) return +i;
return i;
return i.trim();
}).filter((i) => i);
const beginAtMoment = moment.tz(`${beginAtDate} ${beginAtTime}`, this.user.timeZone);
if (!beginAtMoment.isValid()) throw new ValidationError('beginAtDate', 'beginAtTime');
+8 -6
View File
@@ -5,7 +5,7 @@ import AdmZip from 'adm-zip';
import { Time } from '@hydrooj/utils/lib/utils';
import {
ValidationError, HomeworkNotLiveError, ProblemNotFoundError,
HomeworkNotAttendedError, BadRequestError, ContestNotFoundError,
HomeworkNotAttendedError, BadRequestError,
} from '../error';
import {
PenaltyRules, Tdoc, ProblemDoc, User,
@@ -250,8 +250,7 @@ class HomeworkEditHandler extends Handler {
const tdoc = tid
? await contest.get(domainId, tid, document.TYPE_HOMEWORK)
: null;
if (tid && !tdoc) throw new ContestNotFoundError(domainId, tid);
else if (!tid) this.checkPerm(PERM.PERM_CREATE_HOMEWORK);
if (!tid) this.checkPerm(PERM.PERM_CREATE_HOMEWORK);
else if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
else this.checkPerm(PERM.PERM_EDIT_HOMEWORK_SELF);
const extensionDays = tid
@@ -308,10 +307,13 @@ class HomeworkEditHandler extends Handler {
) {
const pids = _pids.replace(/,/g, ',').split(',').map((i) => {
if ((+i).toString() === i) return +i;
return i;
return i.trim();
}).filter((i) => i);
const tdoc = await contest.get(domainId, tid, document.TYPE_HOMEWORK);
if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
const tdoc = tid
? await contest.get(domainId, tid, document.TYPE_HOMEWORK)
: null;
if (!tid) this.checkPerm(PERM.PERM_CREATE_HOMEWORK);
else if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
else this.checkPerm(PERM.PERM_EDIT_HOMEWORK_SELF);
const beginAt = moment.tz(`${beginAtDate} ${beginAtTime}`, this.user.timeZone);
if (!beginAt.isValid()) throw new ValidationError('beginAtDate', 'beginAtTime');
+4 -4
View File
@@ -147,9 +147,9 @@ export function off<K extends keyof EventMap>(name: K, listener: EventMap[K]) {
export async function parallel<K extends keyof EventMap>(name: K, ...args: Parameters<EventMap[K]>): Promise<void> {
const tasks: Promise<any>[] = [];
if (argv.options.showBus) logger.debug('parallel: %s %o', name, args);
if (argv.options.showBus && name !== 'message/log') logger.debug('parallel: %s %o', name, args);
for (const callback of _hooks[name] || []) {
if (argv.options.busDetail) logger.debug(callback.toString());
if (argv.options.busDetail && name !== 'message/log') logger.debug(callback.toString());
tasks.push(callback.apply(this, args));
}
await Promise.all(tasks);
@@ -160,7 +160,7 @@ export function emit<K extends keyof EventMap>(name: K, ...args: Parameters<Even
}
export async function serial<K extends keyof EventMap>(name: K, ...args: Parameters<EventMap[K]>): Promise<void> {
if (argv.options.showBus) logger.debug('serial: %s %o', name, args);
if (argv.options.showBus && name !== 'message/log') logger.debug('serial: %s %o', name, args);
const hooks = Array.from(_hooks[name] || []);
for (const callback of hooks) {
if (argv.options.busDetail) logger.debug(callback.toString());
@@ -169,7 +169,7 @@ export async function serial<K extends keyof EventMap>(name: K, ...args: Paramet
}
export function bail<K extends keyof EventMap>(name: K, ...args: Parameters<EventMap[K]>): ReturnType<EventMap[K]> {
if (argv.options.showBus) logger.debug('bail: %s %o', name, args);
if (argv.options.showBus && name !== 'message/log') logger.debug('bail: %s %o', name, args);
const hooks = Array.from(_hooks[name] || []);
for (const callback of hooks) {
const result = callback.apply(this, args);
+3 -4
View File
@@ -84,13 +84,12 @@ export async function updateJudge(args) {
if (cluster.isMaster) {
bus.on('app/started', async () => {
const info = await sysinfo.get();
await coll.updateOne(
sysinfo.get().then((info) => coll.updateOne(
{ mid: info.mid, type: 'server' },
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
{ upsert: true },
);
await feedback();
));
feedback();
setInterval(update, 60 * 1000);
});
}