core: add provideModule and injectUI API

This commit is contained in:
undefined committed 2022-09-23 01:36:12 +08:00
1 parent 672c553f4c
commit 28f03dbcbd
18 files changed
+211 -97

No files matched your search

+2 -3
View File
@@ -1,9 +1,8 @@
import crypto from 'crypto';
function hash(password: string, salt: string) {
return crypto.pbkdf2Sync(password, salt, 100000, 64, 'sha256').toString('hex').substr(0, 64);
return crypto.pbkdf2Sync(password, salt, 100000, 64, 'sha256').toString('hex').substring(0, 64);
}
export = hash;
global.Hydro.lib['hash.hydro'] = hash;
global.Hydro.module.hash.hydro = hash;
+4 -3
View File
@@ -31,7 +31,9 @@ export const nodes = new Proxy({}, {
},
});
export function inject(node: UIInjectableFields, name: string, args: Record<string, any> = {}, ...permPrivChecker: PermPrivChecker) {
nodes[node].push({ name, args: args || {}, checker: buildChecker(...permPrivChecker) });
const obj = { name, args: args || {}, checker: buildChecker(...permPrivChecker) };
nodes[node].push(obj);
return () => { nodes[node] = nodes[node].filter((i) => i !== obj); };
}
export function getNodes(name: UIInjectableFields) {
return nodes[name];
@@ -65,5 +67,4 @@ inject('ProblemAdd', 'problem_create', { icon: 'add', text: 'Create Problem' });
global.Hydro.ui.inject = inject;
global.Hydro.ui.nodes = nodes as any;
global.Hydro.ui.getNodes = getNodes;
global.Hydro.ui.Nav = Nav;
global.Hydro.ui.ProblemAdd = ProblemAdd;
Object.assign(global.Hydro.ui, { ProblemAdd, Nav });