core: drop global.Hydro.lib

This commit is contained in:
undefined committed 2025-03-10 12:31:25 +08:00
1 parent 1165bfff5b
commit 6ff66f2efc
17 files changed
+31 -45

No files matched your search

+1 -1
View File
@@ -109,7 +109,7 @@ export class ProblemMainHandler extends Handler {
// eslint-disable-next-line @typescript-eslint/no-shadow
const query = this.queryContext.query;
const psdict = {};
const search = global.Hydro.lib.problemSearch || defaultSearch;
const search = Object.values(global.Hydro.module.problemSearch)[0] || defaultSearch;
const parsed = parser.parse(q, {
keywords: ['category', 'difficulty', 'namespace'],
offsets: false,
-2
View File
@@ -11,8 +11,6 @@ if (!global.Hydro) {
// @ts-ignore
model: {},
script: {},
// @ts-ignore
lib: {},
module: new Proxy({} as any, {
get(self, key) {
self[key] ||= {};
+1 -10
View File
@@ -613,15 +613,6 @@ export interface ProblemSearchOptions {
export type ProblemSearch = (domainId: string, q: string, options?: ProblemSearchOptions) => Promise<ProblemSearchResponse>;
export interface Lib extends Record<string, any> {
difficulty: typeof import('./lib/difficulty').default;
buildContent: typeof import('./lib/content').buildContent;
mail: typeof import('./lib/mail');
rating: typeof import('./lib/rating').default;
testdataConfig: typeof import('./lib/testdataConfig');
problemSearch: ProblemSearch;
}
export type UIInjectableFields = 'ProblemAdd' | 'Notification' | 'Nav' | 'UserDropdown' | 'DomainManage' | 'ControlPanel';
export interface UI {
nodes: Record<UIInjectableFields, any[]>,
@@ -638,13 +629,13 @@ export interface ModuleInterfaces {
lockUsername?: boolean;
};
hash: (password: string, salt: string, user: User) => boolean | string | Promise<string>;
problemSearch: ProblemSearch;
}
export interface HydroGlobal {
version: Record<string, string>;
model: Model;
script: Record<string, Script>;
lib: Lib;
module: { [K in keyof ModuleInterfaces]: Record<string, ModuleInterfaces[K]> };
ui: UI;
error: typeof import('./error');
-1
View File
@@ -34,4 +34,3 @@ export function validate(input: string) {
}
export default avatar;
global.Hydro.lib.avatar = avatar;
-2
View File
@@ -76,5 +76,3 @@ export function buildContent(source: ProblemSource, type: 'markdown' | 'html' =
...source.source ? [`## ${_('Source')}`, '', source.source, ''] : [],
].join('\n');
}
global.Hydro.lib.buildContent = buildContent;
-1
View File
@@ -43,4 +43,3 @@ function difficultyAlgorithm(nSubmit: number, nAccept: number) {
}
export default difficultyAlgorithm;
global.Hydro.lib.difficulty = difficultyAlgorithm;
-4
View File
@@ -37,7 +37,3 @@ export async function sendMail(to: string, subject: string, text: string, html:
}
return t;
}
global.Hydro.lib.mail = {
sendMail,
};
-2
View File
@@ -119,5 +119,3 @@ function calculate(users: RatingInputUser[]): RatingOutputUser[] {
}
export default calculate;
global.Hydro.lib.rating = calculate;
@@ -37,5 +37,3 @@ export async function parseConfig(config: string | ProblemConfigFile = {}) {
if (cfg.filename && result.type === 'default') result.subType = cfg.filename;
return result;
}
global.Hydro.lib.testdataConfig = { parseConfig };
+2
View File
@@ -44,6 +44,8 @@ export { default as mime } from './lib/mime';
export { default as difficultyAlgorithm } from './lib/difficulty';
export { default as rating } from './lib/rating';
export { default as avatar } from './lib/avatar';
export { parseConfig as testdataConfig } from './lib/testdataConfig';
export { sendMail } from './lib/mail';
/** @deprecated use Handler.paginate instead */
export const paginate = db.paginate.bind(db);
/** @deprecated use db.ranked instead */
+7 -5
View File
@@ -144,7 +144,7 @@ export default class HMR extends Service {
}
}
private triggerLocalReload() {
private async triggerLocalReload() {
this.analyzeChanges();
/** plugins pending classification */
@@ -207,10 +207,11 @@ export default class HMR extends Service {
return rollback();
}
const reload = (plugin: any, runtime?: Plugin.Runtime) => {
const reload = async (plugin: any, runtime?: Plugin.Runtime) => {
if (!runtime) return;
for (const oldFiber of runtime.scopes) {
oldFiber.parent.plugin(plugin, oldFiber.config);
// eslint-disable-next-line no-await-in-loop
await oldFiber.parent.plugin(plugin, oldFiber.config);
}
};
@@ -226,7 +227,8 @@ export default class HMR extends Service {
}
try {
reload(attempts[filename], runtime);
// eslint-disable-next-line no-await-in-loop
await reload(attempts[filename], runtime);
logger.info('reload plugin at %c', path);
} catch (err) {
logger.warn('failed to reload plugin at %c', path);
@@ -240,7 +242,7 @@ export default class HMR extends Service {
for (const [plugin, { filename, runtime }] of reloads) {
try {
this.ctx.registry.delete(attempts[filename]);
reload(plugin, runtime);
await reload(plugin, runtime);
} catch (err) {
logger.warn(err);
}