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