mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +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
-1
@@ -28,7 +28,7 @@
|
||||
"@shelf/jest-mongodb": "^1.2.3",
|
||||
"@types/cross-spawn": "^6.0.2",
|
||||
"@types/jest": "^26.0.23",
|
||||
"@types/node": "^14.14.41",
|
||||
"@types/node": "^15.0.1",
|
||||
"@types/semver": "^7.3.5",
|
||||
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
||||
"@typescript-eslint/parser": "^4.21.0",
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
"ws": "^7.4.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ws": "^7.4.1"
|
||||
"@types/ws": "^7.4.2"
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.13.14",
|
||||
"@babel/core": "^7.13.14",
|
||||
"@babel/core": "^7.14.0",
|
||||
"@babel/eslint-parser": "7.13.14",
|
||||
"@babel/plugin-proposal-class-properties": "^7.13.0",
|
||||
"@babel/plugin-proposal-export-namespace-from": "^7.12.13",
|
||||
@@ -18,10 +18,10 @@
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
|
||||
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
||||
"@babel/plugin-transform-runtime": "^7.13.10",
|
||||
"@babel/preset-env": "^7.13.10",
|
||||
"@babel/preset-env": "^7.14.0",
|
||||
"@babel/preset-react": "^7.13.13",
|
||||
"@babel/register": "^7.13.14",
|
||||
"@babel/runtime-corejs2": "^7.13.10",
|
||||
"@babel/runtime-corejs2": "^7.14.0",
|
||||
"@hydrooj/utils": "^1.0.7",
|
||||
"ansi_up": "^5.0.1",
|
||||
"autoprefixer": "^9.8.6",
|
||||
|
||||
Reference in new issue
Block a user