core&ui: problem_main: support sort

This commit is contained in:
undefined committed 2025-10-26 23:24:39 +08:00
1 parent e8573d7061
commit 2e9e93c9e1
10 files changed
+46 -16

No files matched your search

+1 -1
View File
@@ -310,7 +310,7 @@ class HomeSecurityHandler extends Handler {
userName: `${this.user.uname}(${this.user.mail})`,
attestationType: 'direct',
excludeCredentials: this.user._authenticators.map((c) => ({
id: isoBase64URL.fromBuffer(c.credentialID.buffer),
id: isoBase64URL.fromBuffer(new Uint8Array(c.credentialID.buffer)),
type: 'public-key',
})),
authenticatorSelection: {
+10 -3
View File
@@ -105,10 +105,12 @@ export class ProblemMainHandler extends Handler {
@param('limit', Types.PositiveInt, true)
@param('pjax', Types.Boolean)
@param('quick', Types.Boolean)
async get(domainId: string, page = 1, q = '', limit: number, pjax = false, quick = false) {
@param('sort', Types.Range(['default', 'recent']), true)
async get(domainId: string, page = 1, q = '', limit: number, pjax = false, quick = false, sortStrategy = 'default') {
this.response.template = 'problem_main.html';
if (!limit || limit > this.ctx.setting.get('pagination.problem') || page > 1) limit = this.ctx.setting.get('pagination.problem');
this.queryContext.query = buildQuery(this.user);
if (sortStrategy === 'recent') this.queryContext.hint = 'basic';
// eslint-disable-next-line ts/no-shadow
const query = this.queryContext.query;
const psdict = {};
@@ -145,11 +147,15 @@ export class ProblemMainHandler extends Handler {
}
const sort = this.queryContext.sort;
await this.ctx.parallel('problem/list', query, this, sort);
const sortKey = ({
default: { sort: 1, docId: 1 },
recent: { docId: -1 },
} as const)[sortStrategy];
let [pdocs, ppcount, pcount] = this.queryContext.fail
? [[], 0, 0]
: await this.paginate(
problem.getMulti(domainId, query, quick ? ['title', 'pid', 'domainId', 'docId'] : undefined)
.sort({ sort: 1, docId: 1 }).hint(this.queryContext.hint),
.sort(sortKey).hint(this.queryContext.hint),
sort.length ? 1 : page, limit,
);
if (total) {
@@ -169,7 +175,7 @@ export class ProblemMainHandler extends Handler {
title: this.renderTitle(this.translate('problem_main')),
fragments: (await Promise.all([
this.renderHTML('partials/problem_list.html', {
page, ppcount, pcount, pdocs, psdict, qs: q,
page, ppcount, pcount, pdocs, psdict, qs: q, sort: sortStrategy,
}),
this.renderHTML('partials/problem_stat.html', { pcount, pcountRelation: this.queryContext.pcountRelation }),
this.renderHTML('partials/problem_lucky.html', { qs: q }),
@@ -184,6 +190,7 @@ export class ProblemMainHandler extends Handler {
pdocs,
psdict,
qs: q,
sort: sortStrategy,
};
}
}
+3 -3
View File
@@ -158,7 +158,7 @@ class UserWebauthnHandler extends Handler {
if (!udoc._id) throw new UserNotFoundError(uname || 'user');
if (!udoc.authn) throw new AuthOperationError('authn', 'disabled');
allowCredentials = udoc._authenticators.map((authenticator) => ({
id: isoBase64URL.fromBuffer(authenticator.credentialID.buffer),
id: isoBase64URL.fromBuffer(new Uint8Array(authenticator.credentialID.buffer)),
}));
uid = udoc._id;
}
@@ -194,8 +194,8 @@ class UserWebauthnHandler extends Handler {
expectedRPID: this.getAuthnHost(),
credential: {
...authenticator,
id: isoBase64URL.fromBuffer(authenticator.credentialID.buffer),
publicKey: authenticator.credentialPublicKey.buffer,
id: isoBase64URL.fromBuffer(new Uint8Array(authenticator.credentialID.buffer)),
publicKey: new Uint8Array(authenticator.credentialPublicKey.buffer),
},
}).catch(() => null);
if (!verification?.verified) throw new ValidationError('authenticator');
+2 -2
View File
@@ -414,9 +414,9 @@ export async function apply(ctx: Context) {
coll.deleteMany({ domainId }),
collStatus.deleteMany({ domainId }),
]));
await db.clearIndexes(coll, ['tag', 'hidden']);
await ctx.db.clearIndexes(coll, ['tag', 'hidden']);
const onlyFor = (docType: number) => ({ partialFilterExpression: { docType } });
await db.ensureIndexes(
await ctx.db.ensureIndexes(
coll,
{ key: { domainId: 1, docType: 1, docId: 1 }, name: 'basic', unique: true },
{ key: { domainId: 1, docType: 1, owner: 1, docId: -1 }, name: 'owner' },