mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
patch
This commit is contained in:
1 parent
ee78271a84
commit
d3deeaeb96
10 files changed
+56
-83
No files matched your search
@@ -199,7 +199,7 @@ class ContestEditHandler extends ContestHandler {
|
|||||||
@param('content', Types.String, isContent)
|
@param('content', Types.String, isContent)
|
||||||
@param('rule', Types.String)
|
@param('rule', Types.String)
|
||||||
@param('pids', Types.String)
|
@param('pids', Types.String)
|
||||||
@param('rated', Types.Boolean, true)
|
@param('rated', Types.Boolean)
|
||||||
async post(
|
async post(
|
||||||
domainId: string, beginAtDate: string, beginAtTime: string, duration: number,
|
domainId: string, beginAtDate: string, beginAtTime: string, duration: number,
|
||||||
title: string, content: string, rule: string, _pids: string, rated = false,
|
title: string, content: string, rule: string, _pids: string, rated = false,
|
||||||
@@ -381,7 +381,7 @@ class ContestCreateHandler extends ContestHandler {
|
|||||||
@param('content', Types.String, isContent)
|
@param('content', Types.String, isContent)
|
||||||
@param('rule', Types.String)
|
@param('rule', Types.String)
|
||||||
@param('pids', Types.String)
|
@param('pids', Types.String)
|
||||||
@param('rated', Types.Boolean, true)
|
@param('rated', Types.Boolean)
|
||||||
async post(
|
async post(
|
||||||
domainId: string, beginAtDate: string, beginAtTime: string, duration: number,
|
domainId: string, beginAtDate: string, beginAtTime: string, duration: number,
|
||||||
title: string, content: string, rule: string, _pids: string, rated = false,
|
title: string, content: string, rule: string, _pids: string, rated = false,
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ class DiscussionCreateHandler extends DiscussionHandler {
|
|||||||
@param('name', Types.String)
|
@param('name', Types.String)
|
||||||
@param('title', Types.String, isTitle)
|
@param('title', Types.String, isTitle)
|
||||||
@param('content', Types.String, isContent)
|
@param('content', Types.String, isContent)
|
||||||
@param('highlight', Types.Boolean, true)
|
@param('highlight', Types.Boolean)
|
||||||
async post(
|
async post(
|
||||||
domainId: string, type: string, _name: string,
|
domainId: string, type: string, _name: string,
|
||||||
title: string, content: string, highlight = false,
|
title: string, content: string, highlight = false,
|
||||||
@@ -317,7 +317,7 @@ class DiscussionEditHandler extends DiscussionHandler {
|
|||||||
@param('did', Types.ObjectID)
|
@param('did', Types.ObjectID)
|
||||||
@param('title', Types.String, isTitle)
|
@param('title', Types.String, isTitle)
|
||||||
@param('content', Types.String, isContent)
|
@param('content', Types.String, isContent)
|
||||||
@param('highlight', Types.Boolean, true)
|
@param('highlight', Types.Boolean)
|
||||||
async postUpdate(
|
async postUpdate(
|
||||||
domainId: string, did: ObjectID, title: string, content: string, highlight = false,
|
domainId: string, did: ObjectID, title: string, content: string, highlight = false,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ class HomeworkCreateHandler extends HomeworkHandler {
|
|||||||
@param('title', Types.String, isTitle)
|
@param('title', Types.String, isTitle)
|
||||||
@param('content', Types.String, isContent)
|
@param('content', Types.String, isContent)
|
||||||
@param('pids', Types.String)
|
@param('pids', Types.String)
|
||||||
@param('rated', Types.Boolean, true)
|
@param('rated', Types.Boolean)
|
||||||
async post(
|
async post(
|
||||||
domainId: string, beginAtDate: string, beginAtTime: string,
|
domainId: string, beginAtDate: string, beginAtTime: string,
|
||||||
penaltySinceDate: string, penaltySinceTime: string, extensionDays: number,
|
penaltySinceDate: string, penaltySinceTime: string, extensionDays: number,
|
||||||
@@ -296,7 +296,7 @@ class HomeworkEditHandler extends HomeworkHandler {
|
|||||||
@param('title', Types.String, isTitle)
|
@param('title', Types.String, isTitle)
|
||||||
@param('content', Types.String, isContent)
|
@param('content', Types.String, isContent)
|
||||||
@param('pids', Types.String)
|
@param('pids', Types.String)
|
||||||
@param('rated', Types.Boolean, true)
|
@param('rated', Types.Boolean)
|
||||||
async post(
|
async post(
|
||||||
domainId: string, tid: ObjectID, beginAtDate: string, beginAtTime: string,
|
domainId: string, tid: ObjectID, beginAtDate: string, beginAtTime: string,
|
||||||
penaltySinceDate: string, penaltySinceTime: string, extensionDays: number,
|
penaltySinceDate: string, penaltySinceTime: string, extensionDays: number,
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { isSafeInteger, flatten } from 'lodash';
|
import { isSafeInteger, flatten } from 'lodash';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
import { ObjectID } from 'mongodb';
|
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 paginate from '../lib/paginate';
|
||||||
import {
|
import {
|
||||||
checkPid, isTitle, isContent, isPid,
|
checkPid, isTitle, isContent, isPid,
|
||||||
@@ -17,16 +23,6 @@ import * as bus from '../service/bus';
|
|||||||
import {
|
import {
|
||||||
Route, Connection, Handler, ConnectionHandler, Types, param, multipart,
|
Route, Connection, Handler, ConnectionHandler, Types, param, multipart,
|
||||||
} from '../service/server';
|
} from '../service/server';
|
||||||
import {
|
|
||||||
NoProblemError, ProblemDataNotFoundError, BadRequestError,
|
|
||||||
SolutionNotFoundError,
|
|
||||||
ProblemNotFoundError,
|
|
||||||
ValidationError,
|
|
||||||
PermissionError,
|
|
||||||
} from '../error';
|
|
||||||
import {
|
|
||||||
Pdoc, User, Rdoc, ProblemConfig,
|
|
||||||
} from '../interface';
|
|
||||||
|
|
||||||
const parseCategory = (value: string) => {
|
const parseCategory = (value: string) => {
|
||||||
if (!value) return [];
|
if (!value) return [];
|
||||||
|
|||||||
@@ -91,7 +91,10 @@ class RecordRejudgeHandler extends Handler {
|
|||||||
async post(domainId: string, rid: ObjectID) {
|
async post(domainId: string, rid: ObjectID) {
|
||||||
this.checkPerm(PERM.PERM_REJUDGE);
|
this.checkPerm(PERM.PERM_REJUDGE);
|
||||||
const rdoc = await record.get(domainId, rid);
|
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();
|
this.back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class UserLoginHandler extends Handler {
|
|||||||
|
|
||||||
@param('uname', Types.String)
|
@param('uname', Types.String)
|
||||||
@param('password', 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) {
|
async post(domainId: string, uname: string, password: string, rememberme = false) {
|
||||||
const udoc = await user.getByUname(domainId, uname);
|
const udoc = await user.getByUname(domainId, uname);
|
||||||
if (!udoc) throw new UserNotFoundError(uname);
|
if (!udoc) throw new UserNotFoundError(uname);
|
||||||
@@ -197,7 +197,7 @@ class UserDeleteHandler extends Handler {
|
|||||||
|
|
||||||
class UserSearchHandler extends Handler {
|
class UserSearchHandler extends Handler {
|
||||||
@param('q', Types.String)
|
@param('q', Types.String)
|
||||||
@param('exectMatch', Types.Boolean, true)
|
@param('exectMatch', Types.Boolean)
|
||||||
async get(domainId: string, q: string, exactMatch = false) {
|
async get(domainId: string, q: string, exactMatch = false) {
|
||||||
let udoc = await user.getById(domainId, parseInt(q, 10));
|
let udoc = await user.getById(domainId, parseInt(q, 10));
|
||||||
const udocs = udoc ? [udoc] : [];
|
const udocs = udoc ? [udoc] : [];
|
||||||
@@ -353,7 +353,7 @@ export async function apply() {
|
|||||||
Route('user_logout', '/logout', UserLogoutHandler, PRIV.PRIV_USER_PROFILE);
|
Route('user_logout', '/logout', UserLogoutHandler, PRIV.PRIV_USER_PROFILE);
|
||||||
Route('user_lostpass', '/lostpass', UserLostPassHandler);
|
Route('user_lostpass', '/lostpass', UserLostPassHandler);
|
||||||
Route('user_lostpass_with_code', '/lostpass/:code', UserLostPassWithCodeHandler);
|
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_delete', '/user/delete', UserDeleteHandler, PRIV.PRIV_USER_PROFILE);
|
||||||
Route('user_detail', '/user/:uid', UserDetailHandler);
|
Route('user_detail', '/user/:uid', UserDetailHandler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,13 +111,15 @@ export async function addTailReply(
|
|||||||
domainId: string, drid: ObjectID,
|
domainId: string, drid: ObjectID,
|
||||||
owner: number, content: string, ip: string,
|
owner: number, content: string, ip: string,
|
||||||
): Promise<[Drdoc, ObjectID]> {
|
): Promise<[Drdoc, ObjectID]> {
|
||||||
let drdoc = await document.get(domainId, document.TYPE_DISCUSSION_REPLY, drid);
|
const [drdoc, subId] = await document.push(
|
||||||
const sid = new ObjectID();
|
domainId, document.TYPE_DISCUSSION_REPLY, drid,
|
||||||
[drdoc] = await Promise.all([
|
'reply', content, owner, { ip },
|
||||||
document.push(domainId, document.TYPE_DISCUSSION_REPLY, drid, 'reply', content, owner, { ip }),
|
);
|
||||||
document.set(domainId, document.TYPE_DISCUSSION, drdoc.parentId, { updateAt: new Date() }),
|
await document.set(
|
||||||
]);
|
domainId, document.TYPE_DISCUSSION, drdoc.parentId,
|
||||||
return [drdoc, sid];
|
{ updateAt: new Date() },
|
||||||
|
);
|
||||||
|
return [drdoc, subId];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTailReply(
|
export function getTailReply(
|
||||||
|
|||||||
+26
-54
@@ -1,9 +1,10 @@
|
|||||||
import { ObjectID } from 'mongodb';
|
import { ObjectID } from 'mongodb';
|
||||||
|
import { Dictionary } from 'lodash';
|
||||||
import { STATUS } from './builtin';
|
import { STATUS } from './builtin';
|
||||||
import * as task from './task';
|
import * as task from './task';
|
||||||
import * as problem from './problem';
|
import * as problem from './problem';
|
||||||
import {
|
import {
|
||||||
Rdoc, TestCase, PretestConfig, ContestInfo,
|
Rdoc, TestCase, PretestConfig, ContestInfo, ProblemConfig,
|
||||||
} from '../interface';
|
} from '../interface';
|
||||||
import { RecordNotFoundError } from '../error';
|
import { RecordNotFoundError } from '../error';
|
||||||
import * as db from '../service/db';
|
import * as db from '../service/db';
|
||||||
@@ -46,14 +47,26 @@ export interface JudgeTask {
|
|||||||
type?: string,
|
type?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function add(
|
export async function get(domainId: string, _id: ObjectID): Promise<Rdoc | null> {
|
||||||
domainId: string, pid: number, uid: number,
|
return await coll.findOne({ domainId, _id });
|
||||||
lang: string, code: string, addTask: boolean, contest?: ContestInfo,
|
}
|
||||||
): Promise<ObjectID>
|
|
||||||
export async function add(
|
export async function judge(domainId: string, rid: ObjectID) {
|
||||||
domainId: string, pid: number, uid: number,
|
const rdoc = await get(domainId, rid);
|
||||||
lang: string, code: string, addTask: boolean, config: PretestConfig,
|
let config: ProblemConfig = rdoc.config;
|
||||||
): Promise<ObjectID>
|
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(
|
export async function add(
|
||||||
domainId: string, pid: number, uid: number,
|
domainId: string, pid: number, uid: number,
|
||||||
lang: string, code: string, addTask: boolean, contestOrConfig?: ContestInfo | PretestConfig,
|
lang: string, code: string, addTask: boolean, contestOrConfig?: ContestInfo | PretestConfig,
|
||||||
@@ -77,28 +90,18 @@ export async function add(
|
|||||||
judgeAt: null,
|
judgeAt: null,
|
||||||
rejudged: false,
|
rejudged: false,
|
||||||
};
|
};
|
||||||
|
if (contestOrConfig) {
|
||||||
if ((contestOrConfig as ContestInfo).type) {
|
if ((contestOrConfig as ContestInfo).type) {
|
||||||
data.contest = contestOrConfig as ContestInfo;
|
data.contest = contestOrConfig as ContestInfo;
|
||||||
} else {
|
} else {
|
||||||
data.config = contestOrConfig as PretestConfig;
|
data.config = contestOrConfig as PretestConfig;
|
||||||
}
|
}
|
||||||
const res = await coll.insertOne(data);
|
|
||||||
if (addTask) {
|
|
||||||
await task.add({
|
|
||||||
type: 'judge',
|
|
||||||
rid: res.insertedId,
|
|
||||||
domainId,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
const res = await coll.insertOne(data);
|
||||||
|
if (addTask) await judge(domainId, res.insertedId);
|
||||||
return 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) {
|
export function getMulti(domainId: string, query: any) {
|
||||||
return coll.find({ ...query, domainId });
|
return coll.find({ ...query, domainId });
|
||||||
}
|
}
|
||||||
@@ -138,7 +141,7 @@ export function count(domainId: string, query: any) {
|
|||||||
|
|
||||||
export async function getList(
|
export async function getList(
|
||||||
domainId: string, rids: ObjectID[], showHidden = false,
|
domainId: string, rids: ObjectID[], showHidden = false,
|
||||||
): Promise<{ [key: string]: Rdoc }> {
|
): Promise<Dictionary<Rdoc>> {
|
||||||
const r = {};
|
const r = {};
|
||||||
for (const rid of rids) {
|
for (const rid of rids) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// 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();
|
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 = {
|
global.Hydro.model.record = {
|
||||||
add,
|
add,
|
||||||
get,
|
get,
|
||||||
@@ -206,5 +179,4 @@ global.Hydro.model.record = {
|
|||||||
getUserInProblemMulti,
|
getUserInProblemMulti,
|
||||||
getByUid,
|
getByUid,
|
||||||
judge,
|
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) {
|
export function folderSize(folderPath: string) {
|
||||||
let size = 0;
|
let size = 0;
|
||||||
const _next = function a(p) {
|
const _next = function a(p: string) {
|
||||||
if (p) {
|
if (p) {
|
||||||
const stats = fs.statSync(p);
|
const stats = fs.statSync(p);
|
||||||
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.10.8",
|
"version": "2.10.9",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
Reference in new issue
Block a user