mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: discussion: DNodeNotFoundError
This commit is contained in:
1 parent
2a3933de1a
commit
d9a65aa8cb
7 files changed
+19
-36
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.24.0",
|
||||
"version": "2.24.1",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
@@ -30,7 +30,7 @@
|
||||
"minio": "7.0.17",
|
||||
"moment-timezone": "^0.5.32",
|
||||
"mongodb": "^3.6.6",
|
||||
"nodemailer": "^6.5.0",
|
||||
"nodemailer": "^6.6.0",
|
||||
"p-queue": "^6.6.2",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"serialize-javascript": "^5.0.1",
|
||||
|
||||
@@ -143,7 +143,7 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
||||
}
|
||||
|
||||
async message(msg) {
|
||||
logger.info('%o', msg);
|
||||
if (msg.key !== 'ping') logger.info('%o', msg);
|
||||
if (msg.key === 'next') await next(msg);
|
||||
else if (msg.key === 'end') {
|
||||
await end({ judger: this.user._id, ...msg });
|
||||
|
||||
@@ -10,7 +10,7 @@ class BlackListModel {
|
||||
static async add(id: string, expire?: Date | number) {
|
||||
let expireAt;
|
||||
if (expire === 0) expireAt = moment().add(1000, 'months').toDate();
|
||||
if (typeof expire === 'number') expireAt = moment().add(expire, 'months').toDate();
|
||||
else if (typeof expire === 'number') expireAt = moment().add(expire, 'months').toDate();
|
||||
else if (expire instanceof Date) expireAt = expire;
|
||||
else expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
|
||||
const res = await coll.findOneAndUpdate(
|
||||
|
||||
@@ -4,7 +4,7 @@ import problem from './problem';
|
||||
import * as contest from './contest';
|
||||
import * as training from './training';
|
||||
import * as document from './document';
|
||||
import { DocumentNotFoundError } from '../error';
|
||||
import { DiscussionNodeNotFoundError, DocumentNotFoundError } from '../error';
|
||||
import { Drdoc, Drrdoc, Document } from '../interface';
|
||||
import { buildProjection } from '../utils';
|
||||
import * as bus from '../service/bus';
|
||||
@@ -225,37 +225,20 @@ export function getNode(domainId: string, _id: string) {
|
||||
|
||||
export async function getVnode(domainId: string, type: number, id: string) {
|
||||
if (type === document.TYPE_PROBLEM) {
|
||||
// @ts-ignore
|
||||
if (Number.isSafeInteger(parseInt(id, 10))) id = parseInt(id, 10);
|
||||
const pdoc = await problem.get(domainId, id);
|
||||
if (!pdoc) return null;
|
||||
const pdoc = await problem.get(domainId, Number.isSafeInteger(+id) ? +id : id);
|
||||
if (!pdoc) throw new DiscussionNodeNotFoundError(id);
|
||||
return { ...pdoc, type, id };
|
||||
}
|
||||
if (type === document.TYPE_CONTEST) {
|
||||
const tdoc = await contest.get(domainId, new ObjectID(id));
|
||||
return { ...tdoc, type, id };
|
||||
}
|
||||
if (type === document.TYPE_DISCUSSION_NODE) {
|
||||
const ndoc = await getNode(domainId, id);
|
||||
return {
|
||||
...ndoc,
|
||||
title: id,
|
||||
type,
|
||||
id,
|
||||
};
|
||||
}
|
||||
if (type === document.TYPE_TRAINING) {
|
||||
const tdoc = await training.get(domainId, new ObjectID(id));
|
||||
return { ...tdoc, type, id };
|
||||
}
|
||||
if (type === document.TYPE_HOMEWORK) {
|
||||
const tdoc = await contest.get(domainId, new ObjectID(id), document.TYPE_HOMEWORK);
|
||||
if ([document.TYPE_CONTEST, document.TYPE_TRAINING, document.TYPE_HOMEWORK].includes(type as any)) {
|
||||
const tdoc = await (type === document.TYPE_TRAINING ? training : contest).get(domainId, new ObjectID(id), type as any);
|
||||
if (!tdoc) throw new DiscussionNodeNotFoundError(id);
|
||||
return { ...tdoc, type, id };
|
||||
}
|
||||
return {
|
||||
title: 'Missing Node',
|
||||
type: 'Unknown',
|
||||
id: new ObjectID(),
|
||||
...await getNode(domainId, id),
|
||||
title: id,
|
||||
type,
|
||||
id,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user