mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
patch
This commit is contained in:
1 parent
ee78271a84
commit
d3deeaeb96
10 files changed
+60
-87
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 [];
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
+30
-58
@@ -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<ObjectID>
|
||||
export async function add(
|
||||
domainId: string, pid: number, uid: number,
|
||||
lang: string, code: string, addTask: boolean, config: PretestConfig,
|
||||
): Promise<ObjectID>
|
||||
export async function get(domainId: string, _id: ObjectID): Promise<Rdoc | null> {
|
||||
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<Rdoc> {
|
||||
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<Dictionary<Rdoc>> {
|
||||
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<Rdoc[]> {
|
||||
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,
|
||||
};
|
||||
+1
-1
@@ -122,7 +122,7 @@ Set.intersection = function Intersection<T>(setA: Set<T>, setB: Set<T>): Set<T>
|
||||
|
||||
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()) {
|
||||
|
||||
+1
-1
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user