From e66d5a0221aab3bf12467d977f1f55696492ee06 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 1 Aug 2020 14:43:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=B4=E6=BC=8Fserver=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hydro/handler/discussion.ts | 2 +- hydro/handler/problem.ts | 6 ++++-- hydro/handler/record.ts | 2 +- hydro/model/discussion.ts | 2 ++ hydro/service/db.ts | 1 + hydro/service/server.ts | 12 ++++++++---- package.json | 2 +- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/hydro/handler/discussion.ts b/hydro/handler/discussion.ts index b0806e99d..2fd7ac46d 100644 --- a/hydro/handler/discussion.ts +++ b/hydro/handler/discussion.ts @@ -61,7 +61,7 @@ class DiscussionHandler extends Handler { // TODO(twd2): do more visibility check eg. contest // TODO(twd2): exclude problem/contest discussions? // TODO(iceboy): continuation based pagination. - if (ObjectID.isValid(name)) name = new ObjectID(name); + if (ObjectID.isValid(name.toString())) name = new ObjectID(name); this.vnode = await discussion.getVnode(domainId, typeMapper[type], name, this); if (this.ddoc) { this.ddoc.parentType = this.ddoc.parentType || this.vnode.type; diff --git a/hydro/handler/problem.ts b/hydro/handler/problem.ts index 232113870..bf09d42d5 100644 --- a/hydro/handler/problem.ts +++ b/hydro/handler/problem.ts @@ -351,6 +351,9 @@ class ProblemSettingsHandler extends ProblemManageHandler { [this.pdoc.title, 'problem_detail', { pid }, true], ['problem_settings', null], ]; + if (this.response.body.config) { + this.response.body.config = yaml.safeDump(this.response.body.config); + } } @param('pid', Types.String, null, parsePid) @@ -386,7 +389,6 @@ class ProblemEditHandler extends ProblemManageHandler { [this.pdoc.title, 'problem_detail', { pid }, true], ['problem_edit', null], ]; - this.response.body.page_name = 'problem_edit'; } @param('title', Types.String, isTitle) @@ -395,7 +397,7 @@ class ProblemEditHandler extends ProblemManageHandler { const pid = checkPid(this.request.body.pid); const pdoc = await problem.get(domainId, this.request.params.pid); await problem.edit(domainId, pdoc.docId, { title, content, pid }); - this.response.redirect = this.url('problem_detail', this.request.params.pid); + this.response.redirect = this.url('problem_detail', { pid: this.request.params.pid }); } } diff --git a/hydro/handler/record.ts b/hydro/handler/record.ts index 4d925b81d..c1563d7bf 100644 --- a/hydro/handler/record.ts +++ b/hydro/handler/record.ts @@ -124,7 +124,7 @@ class RecordMainConnectionHandler extends RecordConnectionHandler { this.domainId, { _id: { $in: rids } }, ).toArray(); for (const rdoc of rdocs) { - this.onRecordChange({ value: rdoc }); + this.onRecordChange({ value: { rdoc } }); } } } diff --git a/hydro/model/discussion.ts b/hydro/model/discussion.ts index 7bedfda71..1c569f9a7 100644 --- a/hydro/model/discussion.ts +++ b/hydro/model/discussion.ts @@ -160,6 +160,8 @@ export function getNode(domainId: string, _id: string) { export async function getVnode(domainId: string, type: number, id: string, handler: any) { 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; if (pdoc.hidden && handler) handler.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN); diff --git a/hydro/service/db.ts b/hydro/service/db.ts index 0ba3b951c..9dc5d780f 100644 --- a/hydro/service/db.ts +++ b/hydro/service/db.ts @@ -14,6 +14,7 @@ export let db: mongodb.Db = null; mongodb.MongoClient.connect(mongourl, { useNewUrlParser: true, useUnifiedTopology: true }) .then((Client) => { db = Client.db(opts.name); + global.Hydro.service.db.db = db; bus.publish('system_database_connected', null); }); diff --git a/hydro/service/server.ts b/hydro/service/server.ts index a975e22d9..dda17ebd8 100644 --- a/hydro/service/server.ts +++ b/hydro/service/server.ts @@ -32,9 +32,9 @@ import * as blacklist from '../model/blacklist'; import * as token from '../model/token'; import * as opcount from '../model/opcount'; -const app = new Koa(); -const server = http.createServer(app.callback()); -const router = new Router(); +export const app = new Koa(); +export const server = http.createServer(app.callback()); +export const router = new Router(); type MethodDecorator = (target: any, name: string, obj: any) => any; type Converter = (value: any) => any; @@ -705,7 +705,8 @@ export function Connection( RouteConnHandler: any, ...permPrivChecker: Array ) { - const sock = sockjs.createServer({ prefix, log: (a, b) => console.log(a, b) }); + const log = argv.debug ? console.log : () => { }; + const sock = sockjs.createServer({ prefix, log }); const checker = Checker(permPrivChecker); sock.on('connection', async (conn) => { const h: Dictionary = new RouteConnHandler(conn); @@ -757,6 +758,9 @@ export async function start() { global.Hydro.service.server = { Types, + app, + server, + router, param, multipart, requireCsrfToken, diff --git a/package.json b/package.json index 61d7dd8f6..a49e2b5e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.11.5", + "version": "2.11.7", "main": "dist/loader.js", "bin": "bin/hydrooj.js", "repository": "https://github.com/hydro-dev/Hydro.git",