core: build with plugins

This commit is contained in:
undefined committed 2025-03-04 10:18:22 +08:00
1 parent dec3170524
commit d72bb2074d
8 files changed
+47 -41

No files matched your search

+1 -1
View File
@@ -197,7 +197,7 @@ export class HandlerCommon<C> {
} }
} }
export class Handler<C> extends HandlerCommon<C> { export class Handler<C = CordisContext> extends HandlerCommon<C> {
loginMethods: any; loginMethods: any;
noCheckPermView = false; noCheckPermView = false;
notUsage = false; notUsage = false;
+1 -1
View File
@@ -128,7 +128,7 @@ bus.on('record/judge', async (rdoc, updated, pdoc) => {
await record.judge(rdoc.domainId, rdocs.map((r) => r._id), priority, {}, { hackRejudge: input }); await record.judge(rdoc.domainId, rdocs.map((r) => r._id), priority, {}, { hackRejudge: input });
} catch (e) { } catch (e) {
next({ next({
rid: rdoc._id, rid: rdoc._id.toString(),
domainId: rdoc.domainId, domainId: rdoc.domainId,
key: 'next', key: 'next',
message: { message: 'Unable to apply hack: {0}', params: [e.message] }, message: { message: 'Unable to apply hack: {0}', params: [e.message] },
+1 -1
View File
@@ -147,7 +147,7 @@ async function preload() {
resolve(ctx); resolve(ctx);
}); });
}); });
}) });
for (const a of [path.resolve(__dirname, '..'), ...getAddons()]) { for (const a of [path.resolve(__dirname, '..'), ...getAddons()]) {
try { try {
// Is a npm package // Is a npm package
+22 -19
View File
@@ -1,6 +1,7 @@
import { Dictionary, escapeRegExp } from 'lodash'; import { Dictionary, escapeRegExp } from 'lodash';
import { LRUCache } from 'lru-cache'; import { LRUCache } from 'lru-cache';
import { Filter } from 'mongodb'; import { Filter } from 'mongodb';
import { Context } from '../context';
import { DomainDoc } from '../interface'; import { DomainDoc } from '../interface';
import bus from '../service/bus'; import bus from '../service/bus';
import db from '../service/db'; import db from '../service/db';
@@ -284,24 +285,26 @@ class DomainModel {
} }
} }
bus.on('ready', () => Promise.all([ export async function apply(ctx: Context) {
db.ensureIndexes( ctx.on('domain/delete-cache', async (domainId: string) => {
coll, const ddoc = await DomainModel.get(domainId);
{ key: { lower: 1 }, name: 'lower', unique: true }, if (!ddoc) return;
), for (const host of ddoc.hosts || []) {
db.ensureIndexes( cache.delete(`host::${host}`);
collUser, }
{ key: { domainId: 1, uid: 1 }, name: 'uid', unique: true }, cache.delete(`id::${domainId}`);
{ key: { domainId: 1, rp: -1, uid: 1 }, name: 'rp', sparse: true }, });
), await Promise.all([
])); db.ensureIndexes(
bus.on('domain/delete-cache', async (domainId: string) => { coll,
const ddoc = await DomainModel.get(domainId); { key: { lower: 1 }, name: 'lower', unique: true },
if (!ddoc) return; ),
for (const host of ddoc.hosts || []) { db.ensureIndexes(
cache.delete(`host::${host}`); collUser,
} { key: { domainId: 1, uid: 1 }, name: 'uid', unique: true },
cache.delete(`id::${domainId}`); { key: { domainId: 1, rp: -1, uid: 1 }, name: 'rp', sparse: true },
}); ),
]);
}
export default DomainModel; export default DomainModel;
global.Hydro.model.domain = DomainModel; global.Hydro.model.domain = DomainModel;
+19 -17
View File
@@ -465,22 +465,24 @@ class UserModel {
} }
} }
bus.on('ready', () => Promise.all([ export async function apply() {
db.ensureIndexes( await Promise.all([
coll, db.ensureIndexes(
{ key: { unameLower: 1 }, name: 'uname', unique: true }, coll,
{ key: { mailLower: 1 }, name: 'mail', unique: true }, { key: { unameLower: 1 }, name: 'uname', unique: true },
), { key: { mailLower: 1 }, name: 'mail', unique: true },
db.ensureIndexes( ),
collV, db.ensureIndexes(
{ key: { unameLower: 1 }, name: 'uname', unique: true }, collV,
{ key: { mailLower: 1 }, name: 'mail', unique: true }, { key: { unameLower: 1 }, name: 'uname', unique: true },
), { key: { mailLower: 1 }, name: 'mail', unique: true },
db.ensureIndexes( ),
collGroup, db.ensureIndexes(
{ key: { domainId: 1, name: 1 }, name: 'name', unique: true }, collGroup,
{ key: { domainId: 1, uids: 1 }, name: 'uid' }, { key: { domainId: 1, name: 1 }, name: 'name', unique: true },
), { key: { domainId: 1, uids: 1 }, name: 'uid' },
])); ),
]);
}
export default UserModel; export default UserModel;
global.Hydro.model.user = UserModel; global.Hydro.model.user = UserModel;
+3
View File
@@ -53,3 +53,6 @@ export * from '@hydrooj/framework/validator';
export * as StorageService from './service/storage'; export * as StorageService from './service/storage';
export { EventMap } from './service/bus'; export { EventMap } from './service/bus';
export { db, pwsh }; export { db, pwsh };
// to load ctx.scoreboard
export { } from './handler/contest';
-1
View File
@@ -5,7 +5,6 @@ import {
ForbiddenError, fs, ObjectId, parseTimeMS, PERM, ProblemConfig, ProblemModel, ForbiddenError, fs, ObjectId, parseTimeMS, PERM, ProblemConfig, ProblemModel,
STATUS, STATUS_SHORT_TEXTS, STATUS_TEXTS, Time, UserModel, STATUS, STATUS_SHORT_TEXTS, STATUS_TEXTS, Time, UserModel,
} from 'hydrooj'; } from 'hydrooj';
import type { } from 'hydrooj/src/handler/contest';
import { ResolverInput } from './interface'; import { ResolverInput } from './interface';
interface IpLoginInfo { interface IpLoginInfo {
-1
View File
@@ -2,7 +2,6 @@ import path from 'path';
import { import {
ContestModel, Context, fs, Handler, ObjectId, PERM, Schema, STATUS, Types, UserModel, ContestModel, Context, fs, Handler, ObjectId, PERM, Schema, STATUS, Types, UserModel,
} from 'hydrooj'; } from 'hydrooj';
import type { } from 'hydrooj/src/handler/contest';
const file = fs.readFileSync(path.join(__dirname, 'public/assets/board.html'), 'utf8'); const file = fs.readFileSync(path.join(__dirname, 'public/assets/board.html'), 'utf8');
const indexJs = file.match(/index-([A-Za-z0-9_-]+)\.js"/)?.[1]; const indexJs = file.match(/index-([A-Za-z0-9_-]+)\.js"/)?.[1];