mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: build with plugins
This commit is contained in:
8 files changed
+47
-41
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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] },
|
||||
|
||||
@@ -147,7 +147,7 @@ async function preload() {
|
||||
resolve(ctx);
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
for (const a of [path.resolve(__dirname, '..'), ...getAddons()]) {
|
||||
try {
|
||||
// Is a npm package
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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';
|
||||
@@ -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 {
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in new issue
Block a user