diff --git a/packages/hydrojudge/src/hosts/vj4.ts b/packages/hydrojudge/src/hosts/vj4.ts index 0db5ef580..1fa407f3a 100644 --- a/packages/hydrojudge/src/hosts/vj4.ts +++ b/packages/hydrojudge/src/hosts/vj4.ts @@ -4,6 +4,7 @@ import axios from 'axios'; import AdmZip from 'adm-zip'; import fs from 'fs-extra'; import WebSocket from 'ws'; +import { noop } from 'lodash'; import * as tmpfs from '../tmpfs'; import log from '../log'; import { compilerText, Queue } from '../utils'; @@ -99,7 +100,7 @@ class JudgeTask { }); } } - for (const clean of this.clean) await clean().catch(); + for (const clean of this.clean) await clean().catch(noop); tmpfs.umount(this.tmpdir); fs.removeSync(this.tmpdir); } @@ -257,7 +258,7 @@ export default class VJ4 { }); }); await fs.unlink(tmpFilePath); - await this.processData(savePath).catch(); + await this.processData(savePath).catch(noop); } catch (e) { if (retry) await this.problemData(domainId, pid, savePath, retry - 1); else throw e; diff --git a/packages/hydrojudge/src/judge/default.ts b/packages/hydrojudge/src/judge/default.ts index f0ff7154a..be4d54bb0 100644 --- a/packages/hydrojudge/src/judge/default.ts +++ b/packages/hydrojudge/src/judge/default.ts @@ -63,7 +63,6 @@ function judgeCase(c) { }); } } else if (status === STATUS.STATUS_RUNTIME_ERROR && code) { - status = STATUS.STATUS_RUNTIME_ERROR; if (code < 32) message = signals[code]; else message = `您的程序返回了 ${code}.`; } diff --git a/packages/hydrojudge/src/sandbox.ts b/packages/hydrojudge/src/sandbox.ts index bda6a2485..3111b1fa4 100644 --- a/packages/hydrojudge/src/sandbox.ts +++ b/packages/hydrojudge/src/sandbox.ts @@ -20,7 +20,7 @@ const statusMap = { }; function proc({ - execute = null, + execute = '', time_limit_ms = 16000, memory_limit_mb = 1024, process_limit = 32, diff --git a/packages/hydrojudge/src/service.ts b/packages/hydrojudge/src/service.ts index 3c7842732..0cacac048 100644 --- a/packages/hydrojudge/src/service.ts +++ b/packages/hydrojudge/src/service.ts @@ -6,6 +6,7 @@ import { ObjectID } from 'bson'; import fs from 'fs-extra'; import { homedir, tmpdir } from 'os'; import AdmZip from 'adm-zip'; +import { noop } from 'lodash'; declare module 'hydrooj/dist/interface' { interface SystemKeys { @@ -83,7 +84,7 @@ async function postInit() { }); }); await fs.unlink(tmpFilePath); - await processData(savePath).catch(); + await processData(savePath).catch(noop); return savePath; } @@ -239,7 +240,7 @@ async function postInit() { } } // eslint-disable-next-line no-await-in-loop - for (const clean of this.clean) await clean().catch(); + for (const clean of this.clean) await clean().catch(noop); tmpfs.umount(this.tmpdir); fs.removeSync(this.tmpdir); } diff --git a/packages/hydrojudge/src/sysinfo.ts b/packages/hydrojudge/src/sysinfo.ts index 0dc97495b..ab863d92a 100644 --- a/packages/hydrojudge/src/sysinfo.ts +++ b/packages/hydrojudge/src/sysinfo.ts @@ -2,6 +2,7 @@ import path from 'path'; import fs from 'fs-extra'; import systeminformation from 'systeminformation'; import { tmpdir } from 'os'; +import { noop } from 'lodash'; import { judge } from './judge/run'; import * as tmpfs from './tmpfs'; @@ -49,7 +50,7 @@ int main(){ tmpfs.mount(context.tmpdir, '64m'); await judge(context).catch((e) => console.error(e)); // eslint-disable-next-line no-await-in-loop - for (const clean of context.clean) await clean().catch(); + for (const clean of context.clean) await clean().catch(noop); tmpfs.umount(context.tmpdir); fs.removeSync(context.tmpdir); } catch (e) { diff --git a/packages/hydrojudge/src/utils.ts b/packages/hydrojudge/src/utils.ts index ecec18ac0..ba8934f57 100644 --- a/packages/hydrojudge/src/utils.ts +++ b/packages/hydrojudge/src/utils.ts @@ -13,6 +13,8 @@ const EMPTY_STR = /^[ \r\n\t]*$/i; export const cmd = parse; +export function noop() { } + export function parseTimeMS(str: string) { const match = TIME_RE.exec(str); if (!match) throw new FormatError(str, ['error parsing time']); diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index c0ec4879f..e940ef06d 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -323,8 +323,8 @@ export class ProblemPretestConnectionHandler extends ConnectionHandler { @param('pid', Types.String) async prepare(domainId: string, pid: string) { const pdoc = await problem.get(domainId, pid); - if (pdoc.hidden) this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN); if (!pdoc) throw new ProblemNotFoundError(domainId, pid); + if (pdoc.hidden) this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN); this.pid = pdoc.docId.toString(); this.domainId = domainId; this.dispose = bus.on('record/change', this.onRecordChange.bind(this)); diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index 77c151a8c..9a150f214 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -1,8 +1,7 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Readable, Writable } from 'stream'; -import { ObjectID } from 'mongodb'; -import fs from 'fs'; -import { Dictionary, NumericDictionary } from 'lodash'; +import type { Readable, Writable } from 'stream'; +import type { ObjectID } from 'mongodb'; +import type fs from 'fs'; +import type { Dictionary, NumericDictionary } from 'lodash'; import type { Pdoc } from './model/problem'; type document = typeof import('./model/document'); diff --git a/packages/hydrooj/src/model/file.ts b/packages/hydrooj/src/model/file.ts index cfa514aec..04623368f 100644 --- a/packages/hydrooj/src/model/file.ts +++ b/packages/hydrooj/src/model/file.ts @@ -55,8 +55,8 @@ export async function getWithSecret(_id: ObjectID, secret: string, reject?: Func const file = await coll.findOne({ _id }); if (!file) throw new NotFoundError(_id); const timestamp = _timestamp(); - if (!(hash(file.secret, timestamp.toString()) === secret)) { - if (!(hash(file.secret, (timestamp - 1).toString()) === secret)) { + if (hash(file.secret, timestamp.toString()) !== secret) { + if (hash(file.secret, (timestamp - 1).toString()) !== secret) { throw new ForbiddenError(); } } diff --git a/packages/hydrooj/src/model/record.ts b/packages/hydrooj/src/model/record.ts index ef8a27e29..f656f613d 100644 --- a/packages/hydrooj/src/model/record.ts +++ b/packages/hydrooj/src/model/record.ts @@ -61,7 +61,7 @@ export async function judge(domainId: string, rid: ObjectID) { if (rdoc.pid) { const pdoc = await problem.get(domainId, rdoc.pid); if (!config) config = pdoc?.config || {}; - data = pdoc.data; + data = pdoc?.data; } delete rdoc._id; await task.add({ diff --git a/packages/hydrooj/src/model/user.ts b/packages/hydrooj/src/model/user.ts index 006acb82c..86f0fa41f 100644 --- a/packages/hydrooj/src/model/user.ts +++ b/packages/hydrooj/src/model/user.ts @@ -129,7 +129,7 @@ export class User implements _User { checkPassword(password: string) { const h = global.Hydro.lib[`hash.${this.hashType}`]; if (!h) throw new Error('Unknown hash method'); - if (!(h(password, this.salt(), this) === this.hash())) { + if (h(password, this.salt(), this) !== this.hash()) { throw new LoginError(this.uname); } else if (this.hashType !== 'hydro') { setPassword(this._id, password); diff --git a/packages/hydrooj/src/service/server.ts b/packages/hydrooj/src/service/server.ts index 77c731c50..aa1d1bd27 100644 --- a/packages/hydrooj/src/service/server.ts +++ b/packages/hydrooj/src/service/server.ts @@ -440,8 +440,7 @@ export class Handler { args.domainId = args.domainId || this.domainId; } const { anchor } = args; - if (query) res = router.url(name, args, { query }); - else res = router.url(name, args); + res = router.url(name, args, { query }); if (anchor) return `${res}#${anchor}`; } catch (e) { console.error(e.message); @@ -563,10 +562,8 @@ export class Handler { this.ctx.response.status = 302; this.ctx.redirect(this.response.redirect); } else { - if (this.response.body != null) { - this.ctx.response.body = this.response.body; - this.ctx.response.status = this.response.status || 200; - } + this.ctx.response.body = this.response.body; + this.ctx.response.status = this.response.status || 200; this.ctx.response.type = this.request.json ? 'application/json' : this.response.type @@ -683,7 +680,7 @@ const Checker = (permPrivChecker) => { if (typeof item === 'object') { if (typeof item.call !== 'undefined') { checker = item; - } if (typeof item[0] === 'number') { + } else if (typeof item[0] === 'number') { priv = item; } else if (typeof item[0] === 'bigint') { perm = item; @@ -772,18 +769,22 @@ export class ConnectionHandler { url(name: string, kwargs: any = {}) { let res = '#'; const args: any = {}; + const query: any = {}; for (const key in kwargs) { if (kwargs[key] instanceof ObjectID) args[key] = kwargs[key].toHexString(); else args[key] = kwargs[key].toString(); } + for (const key in kwargs.query || {}) { + if (query[key] instanceof ObjectID) query[key] = kwargs.query[key].toHexString(); + else query[key] = kwargs.query[key].toString(); + } try { if (this.args.domainId !== 'system' || args.domainId) { name += '_with_domainId'; args.domainId = args.domainId || this.args.domainId; } - const { anchor, query } = args; - if (query) res = router.url(name, args, { query }); - else res = router.url(name, args); + const { anchor } = args; + res = router.url(name, args, { query }); if (anchor) return `${res}#${anchor}`; } catch (e) { console.error(e.message); diff --git a/packages/migrate-vijos/script.ts b/packages/migrate-vijos/script.ts index 048687624..06f038b0b 100644 --- a/packages/migrate-vijos/script.ts +++ b/packages/migrate-vijos/script.ts @@ -401,7 +401,7 @@ async function message(src: Db, report: Function) { } } -async function removeInvalidPid(src: Db, report: Function) { +async function removeInvalidPid(report: Function) { const count = await dst.collection('document').find({ docType: 10 }).count(); const bulk = dst.collection('document').initializeUnorderedBulkOp(); await report({ progress: 1, message: `Remove pid: ${count}` }); @@ -550,7 +550,7 @@ export async function run({ await discussionNode(src, report); await message(src, report); await userfileUsage(src, report); - await removeInvalidPid(src, report); + await removeInvalidPid(report); return true; }