mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: allow cross-domain problem search
This commit is contained in:
1 parent
71a5f6dd13
commit
a0734a1030
11 files changed
+120
-53
No files matched your search
@@ -128,17 +128,22 @@ export class ProblemMainHandler extends ProblemHandler {
|
||||
const query: FilterQuery<ProblemDoc> = {};
|
||||
let psdict = {};
|
||||
const search = global.Hydro.lib.problemSearch;
|
||||
let sort: number[];
|
||||
if (category.length) {
|
||||
query.$and = [];
|
||||
for (const tag of category) query.$and.push({ tag });
|
||||
}
|
||||
let sort: string[];
|
||||
let fail = false;
|
||||
if (category.length) query.$and = category.map((tag) => ({ tag }));
|
||||
if (q) category.push(q);
|
||||
if (category.length) this.extraTitleContent = category.join(',');
|
||||
if (q) {
|
||||
if (search) {
|
||||
const result = await search(domainId, q);
|
||||
query.docId = { $in: result };
|
||||
if (!result.length) fail = true;
|
||||
if (!query.$and) query.$and = [];
|
||||
query.$and.push({
|
||||
$or: result.map((i) => {
|
||||
const [did, docId] = i.split('/');
|
||||
return { domainId: did, docId: +docId };
|
||||
}),
|
||||
});
|
||||
sort = result;
|
||||
} else query.$text = { $search: q };
|
||||
}
|
||||
@@ -147,26 +152,21 @@ export class ProblemMainHandler extends ProblemHandler {
|
||||
}
|
||||
await bus.serial('problem/list', query, this);
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [pdocs, ppcount, pcount] = await paginate(
|
||||
problem.getMulti(domainId, query).sort({ sort: 1, docId: 1 }),
|
||||
page,
|
||||
system.get('pagination.problem'),
|
||||
);
|
||||
if (sort) pdocs = pdocs.sort((a, b) => sort.indexOf(a.docId) - sort.indexOf(b.docId));
|
||||
let [pdocs, ppcount, pcount] = fail
|
||||
? [[], 0, 0]
|
||||
: await problem.list(
|
||||
domainId, query, undefined,
|
||||
page, system.get('pagination.problem'),
|
||||
);
|
||||
if (sort) pdocs = pdocs.sort((a, b) => sort.indexOf(`${a.domainId}/${a.docId}`) - sort.indexOf(`${b.domainId}/${b.docId}`));
|
||||
if (q) {
|
||||
const pdoc = await problem.get(domainId, +q || q, problem.PROJECTION_LIST);
|
||||
if (pdoc) {
|
||||
if (pdoc && (!pdoc.hidden || this.user.own(pdoc) || this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN))) {
|
||||
const count = pdocs.length;
|
||||
pdocs = pdocs.filter((doc) => doc.docId !== pdoc.docId);
|
||||
pdocs.unshift(pdoc);
|
||||
pcount = pcount - count + pdocs.length;
|
||||
}
|
||||
const canViewHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
if (!canViewHidden) {
|
||||
const unshift = [];
|
||||
for (const doc of pdocs) if (doc.hidden && !this.user.own(doc)) unshift.push(doc);
|
||||
for (const task of unshift) pdocs.unshift(task);
|
||||
}
|
||||
}
|
||||
if (this.user.hasPriv(PRIV.PRIV_USER_PROFILE)) {
|
||||
psdict = await problem.getListStatus(
|
||||
|
||||
Reference in new issue
Block a user