mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
Merge branch 'master' into contest-access-lock
This commit is contained in:
commit
73dc91c342
146 files changed
+751
-757
No files matched your search
@@ -2,7 +2,7 @@ import AdmZip from 'adm-zip';
|
||||
import { readFile, statSync } from 'fs-extra';
|
||||
import { isBinaryFile } from 'isbinaryfile';
|
||||
import {
|
||||
escapeRegExp, flattenDeep, intersection, isSafeInteger, pick,
|
||||
escapeRegExp, flattenDeep, intersection, isSafeInteger, pick, uniqBy,
|
||||
} from 'lodash';
|
||||
import { FilterQuery, ObjectID } from 'mongodb';
|
||||
import { nanoid } from 'nanoid';
|
||||
@@ -35,6 +35,7 @@ import * as bus from '../service/bus';
|
||||
import {
|
||||
Handler, param, post, query, route, Types,
|
||||
} from '../service/server';
|
||||
import { buildProjection } from '../utils';
|
||||
import { registerResolver, registerValue } from './api';
|
||||
import { ContestDetailBaseHandler } from './contest';
|
||||
|
||||
@@ -992,18 +993,22 @@ export class ProblemCreateHandler extends Handler {
|
||||
export class ProblemPrefixListHandler extends Handler {
|
||||
@param('prefix', Types.Name)
|
||||
async get(domainId: string, prefix: string) {
|
||||
const pdocs = await problem.getPrefixList(domainId, prefix);
|
||||
if (!Number.isNaN(+prefix) && !pdocs.filter((i) => i.docId === +prefix)) {
|
||||
const pdoc = await problem.get(domainId, +prefix, ['domainId', 'docId', 'pid', 'title']);
|
||||
if (pdoc) pdocs.unshift(pdoc);
|
||||
}
|
||||
const projection = ['domainId', 'docId', 'pid', 'title'] as const;
|
||||
const [pdocs, pdoc, apdoc] = await Promise.all([
|
||||
problem.getPrefixList(domainId, prefix),
|
||||
problem.get(domainId, Number.isSafeInteger(+prefix) ? +prefix : prefix, projection),
|
||||
/^P\d+$/.test(prefix) ? problem.get(domainId, +prefix.substring(1), projection) : Promise.resolve(null),
|
||||
]);
|
||||
if (apdoc) pdocs.unshift(apdoc);
|
||||
if (pdoc) pdocs.unshift(pdoc);
|
||||
if (pdocs.length < 20) {
|
||||
const search = global.Hydro.lib.problemSearch || defaultSearch;
|
||||
const result = await search(domainId, prefix, { limit: 20 - pdocs.length });
|
||||
const docs = await problem.getMulti(domainId, { docId: { $in: result.hits.map((i) => +i.split('/')[1]) } }).toArray();
|
||||
const docs = await problem.getMulti(domainId, { docId: { $in: result.hits.map((i) => +i.split('/')[1]) } })
|
||||
.project(buildProjection(projection)).toArray();
|
||||
pdocs.push(...docs);
|
||||
}
|
||||
this.response.body = pdocs;
|
||||
this.response.body = uniqBy(pdocs, 'docId');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import { sendMail } from '../lib/mail';
|
||||
import { isEmail, isPassword } from '../lib/validator';
|
||||
import BlackListModel from '../model/blacklist';
|
||||
import { PERM, PRIV, STATUS } from '../model/builtin';
|
||||
import * as ContestModel from '../model/contest';
|
||||
import domain from '../model/domain';
|
||||
import oauth from '../model/oauth';
|
||||
import * as oplog from '../model/oplog';
|
||||
@@ -356,9 +357,12 @@ class UserDetailHandler extends Handler {
|
||||
}
|
||||
}
|
||||
const tags = Object.entries(acInfo).sort((a, b) => b[1] - a[1]).slice(0, 20);
|
||||
const tsdocs = await ContestModel.getMultiStatus(domainId, { uid, attend: { $exists: true } }).project({ docId: 1 }).toArray();
|
||||
const tdocs = await ContestModel.getMulti(domainId, { docId: { $in: tsdocs.map((i) => i.docId) } })
|
||||
.project({ docId: 1, title: 1, rule: 1 }).sort({ _id: -1 }).toArray();
|
||||
this.response.template = 'user_detail.html';
|
||||
this.response.body = {
|
||||
isSelfProfile, udoc, sdoc, pdocs, tags,
|
||||
isSelfProfile, udoc, sdoc, pdocs, tags, tdocs,
|
||||
};
|
||||
if (this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION)) {
|
||||
const psdocs = await SolutionModel.getByUser(domainId, uid).limit(10).toArray();
|
||||
|
||||
Reference in new issue
Block a user