mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
Merge branch 'master' into remove-union
This commit is contained in:
17 files changed
+107
-74
No files matched your search
@@ -121,14 +121,12 @@ export class HomeHandler extends Handler {
|
||||
if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) return [[], {}];
|
||||
const psdocs = await ProblemModel.getMultiStatus(domainId, { uid: this.user._id, star: true })
|
||||
.sort('_id', 1).limit(limit).toArray();
|
||||
const psdict = {};
|
||||
for (const psdoc of psdocs) psdict[psdoc.docId] = psdoc;
|
||||
const pdict = await ProblemModel.getList(
|
||||
domainId, psdocs.map((pdoc) => pdoc.docId),
|
||||
this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, false,
|
||||
);
|
||||
const pdocs = Object.keys(pdict).filter((i) => +i).map((i) => pdict[i]);
|
||||
return [pdocs, psdict];
|
||||
return [pdocs];
|
||||
}
|
||||
|
||||
async getRecentProblems(domainId: string, limit = 10) {
|
||||
|
||||
@@ -186,18 +186,6 @@ export class ProblemMainHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
@param('pid', Types.UnsignedInt)
|
||||
async postStar(domainId: string, pid: number) {
|
||||
await problem.setStar(domainId, pid, this.user._id, true);
|
||||
this.back({ star: true });
|
||||
}
|
||||
|
||||
@param('pid', Types.UnsignedInt)
|
||||
async postUnstar(domainId: string, pid: number) {
|
||||
await problem.setStar(domainId, pid, this.user._id, false);
|
||||
this.back({ star: false });
|
||||
}
|
||||
|
||||
@param('pids', Types.NumericArray)
|
||||
@param('target', Types.String)
|
||||
async postCopy(domainId: string, pids: number[], target: string) {
|
||||
@@ -438,6 +426,12 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
|
||||
await problem.del(this.pdoc.domainId, this.pdoc.docId);
|
||||
this.response.redirect = this.url('problem_main');
|
||||
}
|
||||
|
||||
@param('star', Types.Boolean)
|
||||
async postStar(domainId: string, star: boolean) {
|
||||
await problem.setStar(domainId, this.pdoc.docId, this.user._id, star);
|
||||
this.back({ star });
|
||||
}
|
||||
}
|
||||
|
||||
export class ProblemSubmitHandler extends ProblemDetailHandler {
|
||||
|
||||
@@ -7,6 +7,11 @@ declare module '../context' {
|
||||
i18n: I18nService;
|
||||
}
|
||||
}
|
||||
declare module '../service/bus' {
|
||||
interface EventMap {
|
||||
'app/i18n/update': (lang: string) => void;
|
||||
}
|
||||
}
|
||||
declare global {
|
||||
interface String {
|
||||
translate: (...languages: string[]) => string;
|
||||
@@ -22,6 +27,7 @@ class I18nService extends Service {
|
||||
this.ctx.effect(() => {
|
||||
translations[lang] ||= [];
|
||||
translations[lang].unshift(content);
|
||||
this.ctx.emit('app/i18n/update', lang);
|
||||
return () => {
|
||||
translations[lang] = translations[lang].filter((i) => i !== content);
|
||||
};
|
||||
|
||||
@@ -124,12 +124,12 @@ class MongoService {
|
||||
return [pageDocs, numPages, count];
|
||||
}
|
||||
|
||||
async ranked<T extends Record<string, any>>(cursor: FindCursor<T>, equ: (a: T, b: T) => boolean): Promise<[number, T][]> {
|
||||
async ranked<T extends Record<string, any>>(cursor: T[] | FindCursor<T>, equ: (a: T, b: T) => boolean): Promise<[number, T][]> {
|
||||
let last = null;
|
||||
let r = 0;
|
||||
let count = 0;
|
||||
const results = [];
|
||||
const docs = await cursor.toArray();
|
||||
const docs = cursor instanceof Array ? cursor : await cursor.toArray();
|
||||
for (const doc of docs) {
|
||||
if ((doc as any).unrank) {
|
||||
results.push([0, doc]);
|
||||
|
||||
Reference in new issue
Block a user