diff --git a/hydro/handler/contest.ts b/hydro/handler/contest.ts index c47ac5cac..496a2b403 100644 --- a/hydro/handler/contest.ts +++ b/hydro/handler/contest.ts @@ -199,7 +199,7 @@ class ContestEditHandler extends ContestHandler { @param('content', Types.String, isContent) @param('rule', Types.String) @param('pids', Types.String) - @param('rated', Types.Boolean, true) + @param('rated', Types.Boolean) async post( domainId: string, beginAtDate: string, beginAtTime: string, duration: number, title: string, content: string, rule: string, _pids: string, rated = false, @@ -381,7 +381,7 @@ class ContestCreateHandler extends ContestHandler { @param('content', Types.String, isContent) @param('rule', Types.String) @param('pids', Types.String) - @param('rated', Types.Boolean, true) + @param('rated', Types.Boolean) async post( domainId: string, beginAtDate: string, beginAtTime: string, duration: number, title: string, content: string, rule: string, _pids: string, rated = false, diff --git a/hydro/handler/discussion.ts b/hydro/handler/discussion.ts index bbf46fef5..47bf562f5 100644 --- a/hydro/handler/discussion.ts +++ b/hydro/handler/discussion.ts @@ -152,7 +152,7 @@ class DiscussionCreateHandler extends DiscussionHandler { @param('name', Types.String) @param('title', Types.String, isTitle) @param('content', Types.String, isContent) - @param('highlight', Types.Boolean, true) + @param('highlight', Types.Boolean) async post( domainId: string, type: string, _name: string, title: string, content: string, highlight = false, @@ -317,7 +317,7 @@ class DiscussionEditHandler extends DiscussionHandler { @param('did', Types.ObjectID) @param('title', Types.String, isTitle) @param('content', Types.String, isContent) - @param('highlight', Types.Boolean, true) + @param('highlight', Types.Boolean) async postUpdate( domainId: string, did: ObjectID, title: string, content: string, highlight = false, ) { diff --git a/hydro/handler/homework.ts b/hydro/handler/homework.ts index 41c38d2b7..206628e5d 100644 --- a/hydro/handler/homework.ts +++ b/hydro/handler/homework.ts @@ -229,7 +229,7 @@ class HomeworkCreateHandler extends HomeworkHandler { @param('title', Types.String, isTitle) @param('content', Types.String, isContent) @param('pids', Types.String) - @param('rated', Types.Boolean, true) + @param('rated', Types.Boolean) async post( domainId: string, beginAtDate: string, beginAtTime: string, penaltySinceDate: string, penaltySinceTime: string, extensionDays: number, @@ -296,7 +296,7 @@ class HomeworkEditHandler extends HomeworkHandler { @param('title', Types.String, isTitle) @param('content', Types.String, isContent) @param('pids', Types.String) - @param('rated', Types.Boolean, true) + @param('rated', Types.Boolean) async post( domainId: string, tid: ObjectID, beginAtDate: string, beginAtTime: string, penaltySinceDate: string, penaltySinceTime: string, extensionDays: number, diff --git a/hydro/handler/problem.ts b/hydro/handler/problem.ts index be92992aa..a2d90e2a6 100644 --- a/hydro/handler/problem.ts +++ b/hydro/handler/problem.ts @@ -1,6 +1,12 @@ import { isSafeInteger, flatten } from 'lodash'; import yaml from 'js-yaml'; import { ObjectID } from 'mongodb'; +import { + NoProblemError, ProblemDataNotFoundError, BadRequestError, + SolutionNotFoundError, ProblemNotFoundError, ValidationError, + PermissionError, +} from '../error'; +import { Pdoc, User, Rdoc } from '../interface'; import paginate from '../lib/paginate'; import { checkPid, isTitle, isContent, isPid, @@ -17,16 +23,6 @@ import * as bus from '../service/bus'; import { Route, Connection, Handler, ConnectionHandler, Types, param, multipart, } from '../service/server'; -import { - NoProblemError, ProblemDataNotFoundError, BadRequestError, - SolutionNotFoundError, - ProblemNotFoundError, - ValidationError, - PermissionError, -} from '../error'; -import { - Pdoc, User, Rdoc, ProblemConfig, -} from '../interface'; const parseCategory = (value: string) => { if (!value) return []; diff --git a/hydro/handler/record.ts b/hydro/handler/record.ts index c42ac9ada..6a68b62ad 100644 --- a/hydro/handler/record.ts +++ b/hydro/handler/record.ts @@ -91,7 +91,10 @@ class RecordRejudgeHandler extends Handler { async post(domainId: string, rid: ObjectID) { this.checkPerm(PERM.PERM_REJUDGE); const rdoc = await record.get(domainId, rid); - if (rdoc) await record.rejudge(domainId, rid); + if (rdoc) { + await record.reset(domainId, rid, true); + await record.judge(domainId, rid); + } this.back(); } } diff --git a/hydro/handler/user.ts b/hydro/handler/user.ts index 506154c8c..33dc965c8 100644 --- a/hydro/handler/user.ts +++ b/hydro/handler/user.ts @@ -32,7 +32,7 @@ class UserLoginHandler extends Handler { @param('uname', Types.String) @param('password', Types.String) - @param('rememberme', Types.Boolean, true) + @param('rememberme', Types.Boolean) async post(domainId: string, uname: string, password: string, rememberme = false) { const udoc = await user.getByUname(domainId, uname); if (!udoc) throw new UserNotFoundError(uname); @@ -197,7 +197,7 @@ class UserDeleteHandler extends Handler { class UserSearchHandler extends Handler { @param('q', Types.String) - @param('exectMatch', Types.Boolean, true) + @param('exectMatch', Types.Boolean) async get(domainId: string, q: string, exactMatch = false) { let udoc = await user.getById(domainId, parseInt(q, 10)); const udocs = udoc ? [udoc] : []; @@ -353,7 +353,7 @@ export async function apply() { Route('user_logout', '/logout', UserLogoutHandler, PRIV.PRIV_USER_PROFILE); Route('user_lostpass', '/lostpass', UserLostPassHandler); Route('user_lostpass_with_code', '/lostpass/:code', UserLostPassWithCodeHandler); - Route('user_search', '/user/search', UserSearchHandler); + Route('user_search', '/user/search', UserSearchHandler, PRIV.PRIV_USER_PROFILE); Route('user_delete', '/user/delete', UserDeleteHandler, PRIV.PRIV_USER_PROFILE); Route('user_detail', '/user/:uid', UserDetailHandler); } diff --git a/hydro/model/discussion.ts b/hydro/model/discussion.ts index 01d021a0c..37f7bcf8b 100644 --- a/hydro/model/discussion.ts +++ b/hydro/model/discussion.ts @@ -111,13 +111,15 @@ export async function addTailReply( domainId: string, drid: ObjectID, owner: number, content: string, ip: string, ): Promise<[Drdoc, ObjectID]> { - let drdoc = await document.get(domainId, document.TYPE_DISCUSSION_REPLY, drid); - const sid = new ObjectID(); - [drdoc] = await Promise.all([ - document.push(domainId, document.TYPE_DISCUSSION_REPLY, drid, 'reply', content, owner, { ip }), - document.set(domainId, document.TYPE_DISCUSSION, drdoc.parentId, { updateAt: new Date() }), - ]); - return [drdoc, sid]; + const [drdoc, subId] = await document.push( + domainId, document.TYPE_DISCUSSION_REPLY, drid, + 'reply', content, owner, { ip }, + ); + await document.set( + domainId, document.TYPE_DISCUSSION, drdoc.parentId, + { updateAt: new Date() }, + ); + return [drdoc, subId]; } export function getTailReply( diff --git a/hydro/model/record.ts b/hydro/model/record.ts index b27235304..c7c41e98c 100644 --- a/hydro/model/record.ts +++ b/hydro/model/record.ts @@ -1,9 +1,10 @@ import { ObjectID } from 'mongodb'; +import { Dictionary } from 'lodash'; import { STATUS } from './builtin'; import * as task from './task'; import * as problem from './problem'; import { - Rdoc, TestCase, PretestConfig, ContestInfo, + Rdoc, TestCase, PretestConfig, ContestInfo, ProblemConfig, } from '../interface'; import { RecordNotFoundError } from '../error'; import * as db from '../service/db'; @@ -46,14 +47,26 @@ export interface JudgeTask { type?: string, } -export async function add( - domainId: string, pid: number, uid: number, - lang: string, code: string, addTask: boolean, contest?: ContestInfo, -): Promise -export async function add( - domainId: string, pid: number, uid: number, - lang: string, code: string, addTask: boolean, config: PretestConfig, -): Promise +export async function get(domainId: string, _id: ObjectID): Promise { + return await coll.findOne({ domainId, _id }); +} + +export async function judge(domainId: string, rid: ObjectID) { + const rdoc = await get(domainId, rid); + let config: ProblemConfig = rdoc.config; + if (!config) { + const pdoc = await problem.get(domainId, rdoc.pid); + config = pdoc?.config || {}; + } + await task.add({ + ...rdoc, + type: 'judge', + rid, + domainId, + config, + }); +} + export async function add( domainId: string, pid: number, uid: number, lang: string, code: string, addTask: boolean, contestOrConfig?: ContestInfo | PretestConfig, @@ -77,28 +90,18 @@ export async function add( judgeAt: null, rejudged: false, }; - if ((contestOrConfig as ContestInfo).type) { - data.contest = contestOrConfig as ContestInfo; - } else { - data.config = contestOrConfig as PretestConfig; + if (contestOrConfig) { + if ((contestOrConfig as ContestInfo).type) { + data.contest = contestOrConfig as ContestInfo; + } else { + data.config = contestOrConfig as PretestConfig; + } } const res = await coll.insertOne(data); - if (addTask) { - await task.add({ - type: 'judge', - rid: res.insertedId, - domainId, - }); - } + if (addTask) await judge(domainId, res.insertedId); return res.insertedId; } -export async function get(domainId: string, _id: ObjectID): Promise { - const rdoc = await coll.findOne({ domainId, _id }); - if (!rdoc) throw new RecordNotFoundError(_id); - return rdoc; -} - export function getMulti(domainId: string, query: any) { return coll.find({ ...query, domainId }); } @@ -138,7 +141,7 @@ export function count(domainId: string, query: any) { export async function getList( domainId: string, rids: ObjectID[], showHidden = false, -): Promise<{ [key: string]: Rdoc }> { +): Promise> { const r = {}; for (const rid of rids) { // eslint-disable-next-line no-await-in-loop @@ -165,36 +168,6 @@ export function getByUid(domainId: string, uid: number): Promise { return coll.find({ domainId, uid }).toArray(); } -export async function judge(domainId: string, rid: ObjectID) { - const rdoc = await get(domainId, rid); - const pdoc = await problem.get(domainId, rdoc.pid); - await task.add({ - type: 'judge', - rid, - domainId, - config: pdoc.config || '', - pid: rdoc.pid, - data: pdoc.data, - lang: rdoc.lang, - code: rdoc.code, - }); -} - -export async function rejudge(domainId: string, rid: ObjectID) { - await reset(domainId, rid, true); - const rdoc = await get(domainId, rid); - const pdoc = await problem.get(domainId, rdoc.pid); - await task.add({ - type: 'judge', - rid, - domainId, - pid: rdoc.pid, - data: pdoc.data, - lang: rdoc.lang, - code: rdoc.code, - }); -} - global.Hydro.model.record = { add, get, @@ -206,5 +179,4 @@ global.Hydro.model.record = { getUserInProblemMulti, getByUid, judge, - rejudge, }; diff --git a/hydro/utils.ts b/hydro/utils.ts index 6b43f61ee..2c7ee2d9b 100644 --- a/hydro/utils.ts +++ b/hydro/utils.ts @@ -122,7 +122,7 @@ Set.intersection = function Intersection(setA: Set, setB: Set): Set export function folderSize(folderPath: string) { let size = 0; - const _next = function a(p) { + const _next = function a(p: string) { if (p) { const stats = fs.statSync(p); if (!stats.isDirectory() || stats.isSymbolicLink()) { diff --git a/package.json b/package.json index d68581945..10454f32a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.10.8", + "version": "2.10.9", "main": "dist/loader.js", "bin": "bin/hydrooj.js", "repository": "https://github.com/hydro-dev/Hydro.git",