mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
限制用户详情单页提交记录数量
This commit is contained in:
1 parent
9d5b5f1eed
commit
0194ab4eb0
7 files changed
+48
-35
No files matched your search
@@ -37,7 +37,7 @@ class ContestListHandler extends ContestHandler {
|
|||||||
} else {
|
} else {
|
||||||
if (!contest.RULES[rule]) throw new ValidationError('rule');
|
if (!contest.RULES[rule]) throw new ValidationError('rule');
|
||||||
tdocs = contest.getMulti(domainId, { rule }).sort({ beginAt: -1 });
|
tdocs = contest.getMulti(domainId, { rule }).sort({ beginAt: -1 });
|
||||||
qs = 'rule={0}'.format(rule);
|
qs = `rule=${rule}`;
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
[tdocs, tpcount] = await paginate(tdocs, page, await system.get('CONTEST_PER_PAGE'));
|
[tdocs, tpcount] = await paginate(tdocs, page, await system.get('CONTEST_PER_PAGE'));
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import {
|
|||||||
SolutionNotFoundError, ProblemNotFoundError, ValidationError,
|
SolutionNotFoundError, ProblemNotFoundError, ValidationError,
|
||||||
PermissionError,
|
PermissionError,
|
||||||
} from '../error';
|
} from '../error';
|
||||||
import { Pdoc, User, Rdoc } from '../interface';
|
import {
|
||||||
|
Pdoc, User, Rdoc, PathComponent,
|
||||||
|
} from '../interface';
|
||||||
import paginate from '../lib/paginate';
|
import paginate from '../lib/paginate';
|
||||||
import {
|
import {
|
||||||
checkPid, isTitle, isContent, isPid,
|
checkPid, isTitle, isContent, isPid,
|
||||||
@@ -62,7 +64,7 @@ class ProblemMainHandler extends ProblemHandler {
|
|||||||
this.response.template = 'problem_main.html';
|
this.response.template = 'problem_main.html';
|
||||||
const query: any = {};
|
const query: any = {};
|
||||||
let psdict = {};
|
let psdict = {};
|
||||||
const path: any = [
|
const path: PathComponent[] = [
|
||||||
['Hydro', 'homepage'],
|
['Hydro', 'homepage'],
|
||||||
['problem_main', null],
|
['problem_main', null],
|
||||||
];
|
];
|
||||||
|
|||||||
+16
-8
@@ -1,5 +1,10 @@
|
|||||||
import superagent from 'superagent';
|
import superagent from 'superagent';
|
||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
|
import {
|
||||||
|
UserAlreadyExistError, InvalidTokenError, VerifyPasswordError,
|
||||||
|
UserNotFoundError, SystemError, BlacklistedError,
|
||||||
|
UserFacingError,
|
||||||
|
} from '../error';
|
||||||
import {
|
import {
|
||||||
Route, Handler, Types, param,
|
Route, Handler, Types, param,
|
||||||
} from '../service/server';
|
} from '../service/server';
|
||||||
@@ -13,11 +18,7 @@ import { PERM, PRIV } from '../model/builtin';
|
|||||||
import { isEmail, isPassword, isUname } from '../lib/validator';
|
import { isEmail, isPassword, isUname } from '../lib/validator';
|
||||||
import { sendMail } from '../lib/mail';
|
import { sendMail } from '../lib/mail';
|
||||||
import * as misc from '../lib/misc';
|
import * as misc from '../lib/misc';
|
||||||
import {
|
import paginate from '../lib/paginate';
|
||||||
UserAlreadyExistError, InvalidTokenError, VerifyPasswordError,
|
|
||||||
UserNotFoundError, SystemError, BlacklistedError,
|
|
||||||
UserFacingError,
|
|
||||||
} from '../error';
|
|
||||||
|
|
||||||
class UserLoginHandler extends Handler {
|
class UserLoginHandler extends Handler {
|
||||||
async get() {
|
async get() {
|
||||||
@@ -158,8 +159,15 @@ class UserDetailHandler extends Handler {
|
|||||||
const isSelfProfile = this.user._id === uid;
|
const isSelfProfile = this.user._id === uid;
|
||||||
const udoc = await user.getById(domainId, uid);
|
const udoc = await user.getById(domainId, uid);
|
||||||
if (!udoc) throw new UserNotFoundError(uid);
|
if (!udoc) throw new UserNotFoundError(uid);
|
||||||
const sdoc = await token.getMostRecentSessionByUid(uid);
|
const [sdoc, rdocs, [pdocs, pcount]] = await Promise.all([
|
||||||
const rdocs = await record.getByUid(domainId, uid);
|
token.getMostRecentSessionByUid(uid),
|
||||||
|
record.getByUid(domainId, uid, 30),
|
||||||
|
paginate(
|
||||||
|
problem.getMulti(domainId, { owner: this.user._id }),
|
||||||
|
1,
|
||||||
|
100,
|
||||||
|
),
|
||||||
|
]);
|
||||||
const pdict = await problem.getList(
|
const pdict = await problem.getList(
|
||||||
domainId, rdocs.map((rdoc) => rdoc.pid),
|
domainId, rdocs.map((rdoc) => rdoc.pid),
|
||||||
this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), false,
|
this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), false,
|
||||||
@@ -176,7 +184,7 @@ class UserDetailHandler extends Handler {
|
|||||||
];
|
];
|
||||||
this.response.template = 'user_detail.html';
|
this.response.template = 'user_detail.html';
|
||||||
this.response.body = {
|
this.response.body = {
|
||||||
isSelfProfile, udoc, sdoc, rdocs, pdict, path,
|
isSelfProfile, udoc, sdoc, rdocs, pdocs, pcount, pdict, path,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,17 @@ export interface Pdoc {
|
|||||||
|
|
||||||
export type Pdict = NumericDictionary<Pdoc>;
|
export type Pdict = NumericDictionary<Pdoc>;
|
||||||
|
|
||||||
|
export interface ProblemStatusDoc {
|
||||||
|
_id: ObjectID,
|
||||||
|
docId: number,
|
||||||
|
docType: number,
|
||||||
|
domainId: string,
|
||||||
|
uid: number,
|
||||||
|
rid?: ObjectID,
|
||||||
|
status?: number,
|
||||||
|
star?: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
export interface TestCase {
|
export interface TestCase {
|
||||||
time: number,
|
time: number,
|
||||||
memory: number,
|
memory: number,
|
||||||
@@ -338,6 +349,8 @@ export interface JudgeResultBody {
|
|||||||
stderr?: string,
|
stderr?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PathComponent = [string, string, any?, boolean?];
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace NodeJS {
|
namespace NodeJS {
|
||||||
interface Global {
|
interface Global {
|
||||||
|
|||||||
+11
-21
@@ -1,9 +1,12 @@
|
|||||||
import { ObjectID } from 'mongodb';
|
import { ObjectID } from 'mongodb';
|
||||||
|
import { Dictionary } from 'lodash';
|
||||||
import { STATUS } from './builtin';
|
import { STATUS } from './builtin';
|
||||||
import * as file from './file';
|
import * as file from './file';
|
||||||
import * as document from './document';
|
import * as document from './document';
|
||||||
import * as domain from './domain';
|
import * as domain from './domain';
|
||||||
import { Pdoc, Pdict, ProblemDataSource } from '../interface';
|
import {
|
||||||
|
Pdoc, Pdict, ProblemDataSource, ProblemStatusDoc,
|
||||||
|
} from '../interface';
|
||||||
import { ProblemNotFoundError } from '../error';
|
import { ProblemNotFoundError } from '../error';
|
||||||
import * as testdataConfig from '../lib/testdataConfig';
|
import * as testdataConfig from '../lib/testdataConfig';
|
||||||
|
|
||||||
@@ -46,7 +49,7 @@ export async function get(
|
|||||||
uid: number = null,
|
uid: number = null,
|
||||||
): Promise<Pdoc> {
|
): Promise<Pdoc> {
|
||||||
if (typeof pid !== 'number') {
|
if (typeof pid !== 'number') {
|
||||||
if (!Number.isNaN(parseInt(pid, 10))) pid = parseInt(pid, 10);
|
if (!Number.isSafeInteger(parseInt(pid, 10))) pid = parseInt(pid, 10);
|
||||||
}
|
}
|
||||||
const pdoc = Number.isInteger(pid)
|
const pdoc = Number.isInteger(pid)
|
||||||
? await document.get(domainId, document.TYPE_PROBLEM, pid)
|
? await document.get(domainId, document.TYPE_PROBLEM, pid)
|
||||||
@@ -58,14 +61,6 @@ export async function get(
|
|||||||
return pdoc;
|
return pdoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMany(
|
|
||||||
domainId: string, query: any, sort: any, page: number, limit: number,
|
|
||||||
): Promise<Pdoc[]> {
|
|
||||||
return document.getMulti(domainId, query)
|
|
||||||
.sort(sort).skip((page - 1) * limit).limit(limit)
|
|
||||||
.toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getMulti(domainId: string, query: object) {
|
export function getMulti(domainId: string, query: object) {
|
||||||
return document.getMulti(domainId, document.TYPE_PROBLEM, query);
|
return document.getMulti(domainId, document.TYPE_PROBLEM, query);
|
||||||
}
|
}
|
||||||
@@ -128,7 +123,7 @@ export async function getListStatus(domainId: string, uid: number, pids: number[
|
|||||||
const psdocs = await getMultiStatus(
|
const psdocs = await getMultiStatus(
|
||||||
domainId, { uid, docId: { $in: Array.from(new Set(pids)) } },
|
domainId, { uid, docId: { $in: Array.from(new Set(pids)) } },
|
||||||
).toArray();
|
).toArray();
|
||||||
const r = {};
|
const r: Dictionary<ProblemStatusDoc> = {};
|
||||||
for (const psdoc of psdocs) r[psdoc.docId] = psdoc;
|
for (const psdoc of psdocs) r[psdoc.docId] = psdoc;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -137,15 +132,11 @@ export async function updateStatus(
|
|||||||
domainId: string, pid: number, uid: number,
|
domainId: string, pid: number, uid: number,
|
||||||
rid: ObjectID, status: number,
|
rid: ObjectID, status: number,
|
||||||
) {
|
) {
|
||||||
try {
|
const res = await document.setIfNotStatus(
|
||||||
await document.setIfNotStatus(
|
domainId, document.TYPE_PROBLEM, pid, uid,
|
||||||
domainId, document.TYPE_PROBLEM, pid, uid,
|
'status', status, STATUS.STATUS_ACCEPTED, { rid },
|
||||||
'status', status, STATUS.STATUS_ACCEPTED, { rid },
|
);
|
||||||
);
|
return !!res;
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setStar(domainId: string, pid: number, uid: number, star: boolean) {
|
export function setStar(domainId: string, pid: number, uid: number, star: boolean) {
|
||||||
@@ -165,7 +156,6 @@ global.Hydro.model.problem = {
|
|||||||
add,
|
add,
|
||||||
inc,
|
inc,
|
||||||
get,
|
get,
|
||||||
getMany,
|
|
||||||
edit,
|
edit,
|
||||||
count,
|
count,
|
||||||
random,
|
random,
|
||||||
|
|||||||
@@ -171,8 +171,8 @@ export function getUserInProblemMulti(
|
|||||||
return coll.find({ domainId, uid, pid });
|
return coll.find({ domainId, uid, pid });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getByUid(domainId: string, uid: number): Promise<Rdoc[]> {
|
export function getByUid(domainId: string, uid: number, limit: number): Promise<Rdoc[]> {
|
||||||
return coll.find({ domainId, uid }).toArray();
|
return coll.find({ domainId, uid }).limit(limit).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
global.Hydro.model.record = {
|
global.Hydro.model.record = {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.11.4",
|
"version": "2.11.5",
|
||||||
"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