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 {
|
||||
if (!contest.RULES[rule]) throw new ValidationError('rule');
|
||||
tdocs = contest.getMulti(domainId, { rule }).sort({ beginAt: -1 });
|
||||
qs = 'rule={0}'.format(rule);
|
||||
qs = `rule=${rule}`;
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
[tdocs, tpcount] = await paginate(tdocs, page, await system.get('CONTEST_PER_PAGE'));
|
||||
|
||||
@@ -6,7 +6,9 @@ import {
|
||||
SolutionNotFoundError, ProblemNotFoundError, ValidationError,
|
||||
PermissionError,
|
||||
} from '../error';
|
||||
import { Pdoc, User, Rdoc } from '../interface';
|
||||
import {
|
||||
Pdoc, User, Rdoc, PathComponent,
|
||||
} from '../interface';
|
||||
import paginate from '../lib/paginate';
|
||||
import {
|
||||
checkPid, isTitle, isContent, isPid,
|
||||
@@ -62,7 +64,7 @@ class ProblemMainHandler extends ProblemHandler {
|
||||
this.response.template = 'problem_main.html';
|
||||
const query: any = {};
|
||||
let psdict = {};
|
||||
const path: any = [
|
||||
const path: PathComponent[] = [
|
||||
['Hydro', 'homepage'],
|
||||
['problem_main', null],
|
||||
];
|
||||
|
||||
+16
-8
@@ -1,5 +1,10 @@
|
||||
import superagent from 'superagent';
|
||||
import moment from 'moment-timezone';
|
||||
import {
|
||||
UserAlreadyExistError, InvalidTokenError, VerifyPasswordError,
|
||||
UserNotFoundError, SystemError, BlacklistedError,
|
||||
UserFacingError,
|
||||
} from '../error';
|
||||
import {
|
||||
Route, Handler, Types, param,
|
||||
} from '../service/server';
|
||||
@@ -13,11 +18,7 @@ import { PERM, PRIV } from '../model/builtin';
|
||||
import { isEmail, isPassword, isUname } from '../lib/validator';
|
||||
import { sendMail } from '../lib/mail';
|
||||
import * as misc from '../lib/misc';
|
||||
import {
|
||||
UserAlreadyExistError, InvalidTokenError, VerifyPasswordError,
|
||||
UserNotFoundError, SystemError, BlacklistedError,
|
||||
UserFacingError,
|
||||
} from '../error';
|
||||
import paginate from '../lib/paginate';
|
||||
|
||||
class UserLoginHandler extends Handler {
|
||||
async get() {
|
||||
@@ -158,8 +159,15 @@ class UserDetailHandler extends Handler {
|
||||
const isSelfProfile = this.user._id === uid;
|
||||
const udoc = await user.getById(domainId, uid);
|
||||
if (!udoc) throw new UserNotFoundError(uid);
|
||||
const sdoc = await token.getMostRecentSessionByUid(uid);
|
||||
const rdocs = await record.getByUid(domainId, uid);
|
||||
const [sdoc, rdocs, [pdocs, pcount]] = await Promise.all([
|
||||
token.getMostRecentSessionByUid(uid),
|
||||
record.getByUid(domainId, uid, 30),
|
||||
paginate(
|
||||
problem.getMulti(domainId, { owner: this.user._id }),
|
||||
1,
|
||||
100,
|
||||
),
|
||||
]);
|
||||
const pdict = await problem.getList(
|
||||
domainId, rdocs.map((rdoc) => rdoc.pid),
|
||||
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.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 interface ProblemStatusDoc {
|
||||
_id: ObjectID,
|
||||
docId: number,
|
||||
docType: number,
|
||||
domainId: string,
|
||||
uid: number,
|
||||
rid?: ObjectID,
|
||||
status?: number,
|
||||
star?: boolean,
|
||||
}
|
||||
|
||||
export interface TestCase {
|
||||
time: number,
|
||||
memory: number,
|
||||
@@ -338,6 +349,8 @@ export interface JudgeResultBody {
|
||||
stderr?: string,
|
||||
}
|
||||
|
||||
export type PathComponent = [string, string, any?, boolean?];
|
||||
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
|
||||
+11
-21
@@ -1,9 +1,12 @@
|
||||
import { ObjectID } from 'mongodb';
|
||||
import { Dictionary } from 'lodash';
|
||||
import { STATUS } from './builtin';
|
||||
import * as file from './file';
|
||||
import * as document from './document';
|
||||
import * as domain from './domain';
|
||||
import { Pdoc, Pdict, ProblemDataSource } from '../interface';
|
||||
import {
|
||||
Pdoc, Pdict, ProblemDataSource, ProblemStatusDoc,
|
||||
} from '../interface';
|
||||
import { ProblemNotFoundError } from '../error';
|
||||
import * as testdataConfig from '../lib/testdataConfig';
|
||||
|
||||
@@ -46,7 +49,7 @@ export async function get(
|
||||
uid: number = null,
|
||||
): Promise<Pdoc> {
|
||||
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)
|
||||
? await document.get(domainId, document.TYPE_PROBLEM, pid)
|
||||
@@ -58,14 +61,6 @@ export async function get(
|
||||
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) {
|
||||
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(
|
||||
domainId, { uid, docId: { $in: Array.from(new Set(pids)) } },
|
||||
).toArray();
|
||||
const r = {};
|
||||
const r: Dictionary<ProblemStatusDoc> = {};
|
||||
for (const psdoc of psdocs) r[psdoc.docId] = psdoc;
|
||||
return r;
|
||||
}
|
||||
@@ -137,15 +132,11 @@ export async function updateStatus(
|
||||
domainId: string, pid: number, uid: number,
|
||||
rid: ObjectID, status: number,
|
||||
) {
|
||||
try {
|
||||
await document.setIfNotStatus(
|
||||
domainId, document.TYPE_PROBLEM, pid, uid,
|
||||
'status', status, STATUS.STATUS_ACCEPTED, { rid },
|
||||
);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
const res = await document.setIfNotStatus(
|
||||
domainId, document.TYPE_PROBLEM, pid, uid,
|
||||
'status', status, STATUS.STATUS_ACCEPTED, { rid },
|
||||
);
|
||||
return !!res;
|
||||
}
|
||||
|
||||
export function setStar(domainId: string, pid: number, uid: number, star: boolean) {
|
||||
@@ -165,7 +156,6 @@ global.Hydro.model.problem = {
|
||||
add,
|
||||
inc,
|
||||
get,
|
||||
getMany,
|
||||
edit,
|
||||
count,
|
||||
random,
|
||||
|
||||
@@ -171,8 +171,8 @@ export function getUserInProblemMulti(
|
||||
return coll.find({ domainId, uid, pid });
|
||||
}
|
||||
|
||||
export function getByUid(domainId: string, uid: number): Promise<Rdoc[]> {
|
||||
return coll.find({ domainId, uid }).toArray();
|
||||
export function getByUid(domainId: string, uid: number, limit: number): Promise<Rdoc[]> {
|
||||
return coll.find({ domainId, uid }).limit(limit).toArray();
|
||||
}
|
||||
|
||||
global.Hydro.model.record = {
|
||||
|
||||
Reference in new issue
Block a user