core: discussion: DNodeNotFoundError

pull/126/head
undefined 3 years ago
parent 2a3933de1a
commit d9a65aa8cb

@ -28,7 +28,7 @@
"@shelf/jest-mongodb": "^1.2.3", "@shelf/jest-mongodb": "^1.2.3",
"@types/cross-spawn": "^6.0.2", "@types/cross-spawn": "^6.0.2",
"@types/jest": "^26.0.23", "@types/jest": "^26.0.23",
"@types/node": "^14.14.41", "@types/node": "^15.0.1",
"@types/semver": "^7.3.5", "@types/semver": "^7.3.5",
"@typescript-eslint/eslint-plugin": "^4.21.0", "@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0", "@typescript-eslint/parser": "^4.21.0",

@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.24.0", "version": "2.24.1",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
@ -30,7 +30,7 @@
"minio": "7.0.17", "minio": "7.0.17",
"moment-timezone": "^0.5.32", "moment-timezone": "^0.5.32",
"mongodb": "^3.6.6", "mongodb": "^3.6.6",
"nodemailer": "^6.5.0", "nodemailer": "^6.6.0",
"p-queue": "^6.6.2", "p-queue": "^6.6.2",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"serialize-javascript": "^5.0.1", "serialize-javascript": "^5.0.1",

@ -143,7 +143,7 @@ class JudgeConnectionHandler extends ConnectionHandler {
} }
async message(msg) { async message(msg) {
logger.info('%o', msg); if (msg.key !== 'ping') logger.info('%o', msg);
if (msg.key === 'next') await next(msg); if (msg.key === 'next') await next(msg);
else if (msg.key === 'end') { else if (msg.key === 'end') {
await end({ judger: this.user._id, ...msg }); await end({ judger: this.user._id, ...msg });

@ -10,7 +10,7 @@ class BlackListModel {
static async add(id: string, expire?: Date | number) { static async add(id: string, expire?: Date | number) {
let expireAt; let expireAt;
if (expire === 0) expireAt = moment().add(1000, 'months').toDate(); 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 if (expire instanceof Date) expireAt = expire;
else expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000); else expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
const res = await coll.findOneAndUpdate( const res = await coll.findOneAndUpdate(

@ -4,7 +4,7 @@ import problem from './problem';
import * as contest from './contest'; import * as contest from './contest';
import * as training from './training'; import * as training from './training';
import * as document from './document'; import * as document from './document';
import { DocumentNotFoundError } from '../error'; import { DiscussionNodeNotFoundError, DocumentNotFoundError } from '../error';
import { Drdoc, Drrdoc, Document } from '../interface'; import { Drdoc, Drrdoc, Document } from '../interface';
import { buildProjection } from '../utils'; import { buildProjection } from '../utils';
import * as bus from '../service/bus'; 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) { export async function getVnode(domainId: string, type: number, id: string) {
if (type === document.TYPE_PROBLEM) { if (type === document.TYPE_PROBLEM) {
// @ts-ignore const pdoc = await problem.get(domainId, Number.isSafeInteger(+id) ? +id : id);
if (Number.isSafeInteger(parseInt(id, 10))) id = parseInt(id, 10); if (!pdoc) throw new DiscussionNodeNotFoundError(id);
const pdoc = await problem.get(domainId, id);
if (!pdoc) return null;
return { ...pdoc, type, id }; return { ...pdoc, type, id };
} }
if (type === document.TYPE_CONTEST) { if ([document.TYPE_CONTEST, document.TYPE_TRAINING, document.TYPE_HOMEWORK].includes(type as any)) {
const tdoc = await contest.get(domainId, new ObjectID(id)); const tdoc = await (type === document.TYPE_TRAINING ? training : contest).get(domainId, new ObjectID(id), type as any);
return { ...tdoc, type, id }; if (!tdoc) throw new DiscussionNodeNotFoundError(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);
return { ...tdoc, type, id }; return { ...tdoc, type, id };
} }
return { return {
title: 'Missing Node', ...await getNode(domainId, id),
type: 'Unknown', title: id,
id: new ObjectID(), type,
id,
}; };
} }

@ -9,6 +9,6 @@
"ws": "^7.4.5" "ws": "^7.4.5"
}, },
"devDependencies": { "devDependencies": {
"@types/ws": "^7.4.1" "@types/ws": "^7.4.2"
} }
} }

@ -7,7 +7,7 @@
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.13.14", "@babel/cli": "^7.13.14",
"@babel/core": "^7.13.14", "@babel/core": "^7.14.0",
"@babel/eslint-parser": "7.13.14", "@babel/eslint-parser": "7.13.14",
"@babel/plugin-proposal-class-properties": "^7.13.0", "@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-export-namespace-from": "^7.12.13", "@babel/plugin-proposal-export-namespace-from": "^7.12.13",
@ -18,10 +18,10 @@
"@babel/plugin-syntax-dynamic-import": "^7.0.0", "@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.10.4", "@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-transform-runtime": "^7.13.10", "@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/preset-react": "^7.13.13",
"@babel/register": "^7.13.14", "@babel/register": "^7.13.14",
"@babel/runtime-corejs2": "^7.13.10", "@babel/runtime-corejs2": "^7.14.0",
"@hydrooj/utils": "^1.0.7", "@hydrooj/utils": "^1.0.7",
"ansi_up": "^5.0.1", "ansi_up": "^5.0.1",
"autoprefixer": "^9.8.6", "autoprefixer": "^9.8.6",

Loading…
Cancel
Save