mirror of
https://github.com/certd/certd.git
synced 2025-11-25 09:10:11 +08:00
refactor(core): 重构访问控制和插件实例化逻辑
- 修改访问控制和插件注册方式,使用异步函数统一实例化逻辑 - 更新相关组件和控制器以适应新的异步实例化方式 - 优化 DNS 提供商选择器,增加访问类型支持
This commit is contained in:
@@ -26,7 +26,9 @@ export function IsAccess(define: AccessDefine): ClassDecorator {
|
||||
target.define = define;
|
||||
accessRegistry.register(define.name, {
|
||||
define,
|
||||
target,
|
||||
target: async () => {
|
||||
return target;
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -39,13 +41,15 @@ export function AccessInput(input?: AccessInputDefine): PropertyDecorator {
|
||||
};
|
||||
}
|
||||
|
||||
export function newAccess(type: string, input: any, ctx?: AccessContext) {
|
||||
export async function newAccess(type: string, input: any, ctx?: AccessContext) {
|
||||
const register = accessRegistry.get(type);
|
||||
if (register == null) {
|
||||
throw new Error(`access ${type} not found`);
|
||||
}
|
||||
// @ts-ignore
|
||||
const access = new register.target();
|
||||
const accessCls = await register.target();
|
||||
// @ts-ignore
|
||||
const access = new accessCls();
|
||||
for (const key in input) {
|
||||
access[key] = input[key];
|
||||
}
|
||||
|
||||
@@ -281,13 +281,9 @@ export class Executor {
|
||||
let instance: ITaskPlugin = null;
|
||||
try {
|
||||
//@ts-ignore
|
||||
if (plugin.target.define) {
|
||||
//@ts-ignore
|
||||
instance = new plugin.target();
|
||||
} else {
|
||||
//@ts-ignore
|
||||
instance = await plugin.target();
|
||||
}
|
||||
const pluginCls = await plugin.target();
|
||||
//@ts-ignore
|
||||
instance = new pluginCls();
|
||||
} catch (e: any) {
|
||||
currentLogger.error(`实例化插件失败:${e.message}`);
|
||||
throw new Error(`实例化插件失败`, e);
|
||||
|
||||
@@ -26,7 +26,9 @@ export function IsNotification(define: NotificationDefine): ClassDecorator {
|
||||
target.define = define;
|
||||
notificationRegistry.register(define.name, {
|
||||
define,
|
||||
target,
|
||||
target: async () => {
|
||||
return target;
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -44,9 +46,10 @@ export async function newNotification(type: string, input: any, ctx: Notificatio
|
||||
if (register == null) {
|
||||
throw new Error(`notification ${type} not found`);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const plugin = new register.target();
|
||||
const pluginCls = await register.target();
|
||||
// @ts-ignore
|
||||
const plugin = new pluginCls();
|
||||
merge(plugin, input);
|
||||
if (!ctx) {
|
||||
throw new Error("ctx is required");
|
||||
|
||||
@@ -65,7 +65,9 @@ export function IsTaskPlugin(define: PluginDefine): ClassDecorator {
|
||||
|
||||
pluginRegistry.register(define.name, {
|
||||
define,
|
||||
target,
|
||||
target: async () => {
|
||||
return target;
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export type Registrable = {
|
||||
export type TargetGetter<T> = () => Promise<T>;
|
||||
export type RegistryItem<T> = {
|
||||
define: Registrable;
|
||||
target: T | TargetGetter<T>;
|
||||
target: TargetGetter<T>;
|
||||
};
|
||||
|
||||
export type OnRegisterContext<T> = {
|
||||
|
||||
Reference in New Issue
Block a user