mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: 添加app/load钩子
This commit is contained in:
1 parent
ce0357d9bd
commit
e5ed861f1b
10 files changed
+44
-19
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.13.11",
|
||||
"version": "2.13.12",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -4,6 +4,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import yaml from 'js-yaml';
|
||||
import { Logger } from '../logger';
|
||||
import * as bus from '../service/bus';
|
||||
|
||||
const logger = new Logger('common', true);
|
||||
|
||||
@@ -57,6 +58,7 @@ export async function handler(pending: string[], fail: string[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
await bus.serial('app/load/handler');
|
||||
}
|
||||
|
||||
export async function locale(pending: string[], fail: string[]) {
|
||||
@@ -80,6 +82,7 @@ export async function locale(pending: string[], fail: string[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
await bus.serial('app/load/locale');
|
||||
}
|
||||
|
||||
export async function setting(pending: string[], fail: string[], modelSetting: typeof import('../model/setting')) {
|
||||
@@ -110,6 +113,7 @@ export async function setting(pending: string[], fail: string[], modelSetting: t
|
||||
}
|
||||
}
|
||||
}
|
||||
await bus.serial('app/load/setting');
|
||||
}
|
||||
|
||||
export async function template(pending: string[], fail: string[]) {
|
||||
@@ -132,6 +136,7 @@ export async function template(pending: string[], fail: string[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
await bus.serial('app/load/template');
|
||||
}
|
||||
|
||||
export async function uistatic(pending: string[], fail: string[]) {
|
||||
@@ -161,6 +166,7 @@ export async function model(pending: string[], fail: string[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
await bus.serial('app/load/model');
|
||||
}
|
||||
|
||||
export async function lib(pending: string[], fail: string[]) {
|
||||
@@ -177,6 +183,7 @@ export async function lib(pending: string[], fail: string[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
await bus.serial('app/load/lib');
|
||||
}
|
||||
|
||||
export async function service(pending: string[], fail: string[]) {
|
||||
@@ -193,6 +200,7 @@ export async function service(pending: string[], fail: string[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
await bus.serial('app/load/service');
|
||||
}
|
||||
|
||||
export async function script(pending: string[], fail: string[], active: string[]) {
|
||||
@@ -210,4 +218,5 @@ export async function script(pending: string[], fail: string[], active: string[]
|
||||
}
|
||||
active.push(i);
|
||||
}
|
||||
await bus.serial('app/load/script');
|
||||
}
|
||||
@@ -5,14 +5,6 @@ import { Dictionary, NumericDictionary } from 'lodash';
|
||||
|
||||
type document = typeof import('./model/document');
|
||||
|
||||
export type NumberKeys<O> = {
|
||||
[K in keyof O]: number extends O[K] ? K : never
|
||||
}[keyof O];
|
||||
|
||||
export type ArrayKeys<O, P = any> = {
|
||||
[K in keyof O]: P[] extends O[K] ? K : never
|
||||
}[keyof O]
|
||||
|
||||
export interface System {
|
||||
_id: string,
|
||||
value: any,
|
||||
|
||||
@@ -3,11 +3,12 @@ import assert from 'assert';
|
||||
import {
|
||||
ObjectID, Cursor, FilterQuery, UpdateQuery,
|
||||
} from 'mongodb';
|
||||
import {
|
||||
Pdoc, Ddoc, Drdoc, Tdoc, TrainingDoc, ProblemStatusDoc,
|
||||
} from '../interface';
|
||||
import { NumberKeys, ArrayKeys } from '../typeutils';
|
||||
import * as db from '../service/db';
|
||||
import * as bus from '../service/bus';
|
||||
import {
|
||||
Pdoc, Ddoc, Drdoc, Tdoc, TrainingDoc, NumberKeys, ArrayKeys, ProblemStatusDoc,
|
||||
} from '../interface';
|
||||
|
||||
type DocID = ObjectID | string | number;
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@ import * as file from './file';
|
||||
import * as document from './document';
|
||||
import * as domain from './domain';
|
||||
import {
|
||||
Pdoc, Pdict, ProblemDataSource, ProblemStatusDoc, NumberKeys,
|
||||
Pdoc, Pdict, ProblemDataSource, ProblemStatusDoc,
|
||||
} from '../interface';
|
||||
import { NumberKeys } from '../typeutils';
|
||||
import { ProblemNotFoundError } from '../error';
|
||||
import * as testdataConfig from '../lib/testdataConfig';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Lru from 'lru-cache';
|
||||
import { NumberKeys, SystemKeys } from '../interface';
|
||||
import { NumberKeys } from '../typeutils';
|
||||
import { SystemKeys } from '../interface';
|
||||
import * as db from '../service/db';
|
||||
|
||||
const coll = db.collection('system');
|
||||
|
||||
@@ -6,6 +6,7 @@ import * as domain from './domain';
|
||||
import { BUILTIN_USERS, PRIV } from './builtin';
|
||||
import { UserNotFoundError, UserAlreadyExistError, LoginError } from '../error';
|
||||
import { User as _User, Udoc, Udict } from '../interface';
|
||||
import { Value } from '../typeutils';
|
||||
import pwhash from '../lib/hash.hydro';
|
||||
import * as db from '../service/db';
|
||||
import * as bus from '../service/bus';
|
||||
@@ -172,11 +173,11 @@ export async function getByEmail(domainId: string, mail: string): Promise<User |
|
||||
return new User(udoc, dudoc);
|
||||
}
|
||||
|
||||
export function setById(uid: number, $set = {}, $unset = {}) {
|
||||
export async function setById(uid: number, $set?: Partial<Udoc>, $unset?: Value<Partial<Udoc>, ''>) {
|
||||
const op: any = {};
|
||||
if ($set && Object.keys($set).length) op.$set = $set;
|
||||
if ($unset && Object.keys($unset).length) op.$unset = $unset;
|
||||
return coll.findOneAndUpdate({ _id: uid }, op);
|
||||
return await coll.findOneAndUpdate({ _id: uid }, op);
|
||||
}
|
||||
|
||||
export function setEmail(uid: number, mail: string) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import { Udoc } from '../interface';
|
||||
import { Value } from '../typeutils';
|
||||
import * as user from '../model/user';
|
||||
import * as document from '../model/document';
|
||||
import * as setting from '../model/setting';
|
||||
@@ -12,7 +14,7 @@ const collDocument = db.collection('document');
|
||||
const collDomainUser = db.collection('domain.user');
|
||||
const collRecord = db.collection('record');
|
||||
|
||||
const $unset = {
|
||||
const $unset: Value<Partial<Udoc>> = {
|
||||
regip: '', regat: '', loginat: '', loginip: '',
|
||||
};
|
||||
for (const s of setting.PREFERENCE_SETTINGS) {
|
||||
|
||||
@@ -20,8 +20,15 @@ export type VoidReturn = Promise<void> | void
|
||||
|
||||
export interface EventMap {
|
||||
'app/started': () => void
|
||||
'app/exit': () => Promise<void> | void
|
||||
'dispose': () => void
|
||||
'app/load/lib': () => VoidReturn
|
||||
'app/load/locale': () => VoidReturn
|
||||
'app/load/template': () => VoidReturn
|
||||
'app/load/script': () => VoidReturn
|
||||
'app/load/setting': () => VoidReturn
|
||||
'app/load/model': () => VoidReturn
|
||||
'app/load/handler': () => VoidReturn
|
||||
'app/load/service': () => VoidReturn
|
||||
'app/exit': () => VoidReturn
|
||||
|
||||
'database/connect': (db: Db) => void
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
export type NumberKeys<O> = {
|
||||
[K in keyof O]: number extends O[K] ? K : never
|
||||
}[keyof O];
|
||||
|
||||
export type ArrayKeys<O, P = any> = {
|
||||
[K in keyof O]: P[] extends O[K] ? K : never
|
||||
}[keyof O]
|
||||
|
||||
export type Value<O, V = ''> = {
|
||||
[K in keyof O]: V
|
||||
}
|
||||
Reference in new issue
Block a user