mirror of
https://github.com/certd/certd.git
synced 2026-07-02 01:17:32 +08:00
feat: 通过插件配置懒加载依赖,动态加载第三方依赖包,精简安装镜像大小
This commit is contained in:
@@ -3,7 +3,7 @@ import { Registrable } from "../registry/index.js";
|
||||
import { FormItemProps, HistoryResult, Pipeline } from "../dt/index.js";
|
||||
import { HttpClient, ILogger, utils } from "@certd/basic";
|
||||
import * as _ from "lodash-es";
|
||||
import { IEmailService } from "../service/index.js";
|
||||
import { IEmailService, IServiceGetter } from "../service/index.js";
|
||||
|
||||
export type NotificationBody = {
|
||||
userId?: number;
|
||||
@@ -39,6 +39,8 @@ export type NotificationInputDefine = FormItemProps & {
|
||||
};
|
||||
export type NotificationDefine = Registrable & {
|
||||
needPlus?: boolean;
|
||||
dependPlugins?: Record<string, string>;
|
||||
dependPackages?: Record<string, string>;
|
||||
input?: {
|
||||
[key: string]: NotificationInputDefine;
|
||||
};
|
||||
@@ -78,6 +80,8 @@ export type NotificationContext = {
|
||||
logger: ILogger;
|
||||
utils: typeof utils;
|
||||
emailService: IEmailService;
|
||||
serviceGetter?: IServiceGetter;
|
||||
define?: NotificationDefine;
|
||||
};
|
||||
|
||||
export abstract class BaseNotification implements INotification {
|
||||
@@ -85,6 +89,17 @@ export abstract class BaseNotification implements INotification {
|
||||
ctx!: NotificationContext;
|
||||
http!: HttpClient;
|
||||
logger!: ILogger;
|
||||
runtimeDepsService?: {
|
||||
ensureRuntimeDependencies(pluginKeys: string | string[]): Promise<any>;
|
||||
importRuntime(specifier: string): Promise<any>;
|
||||
};
|
||||
|
||||
async importRuntime(specifier: string) {
|
||||
if (!this.runtimeDepsService) {
|
||||
return await import(specifier);
|
||||
}
|
||||
return await this.runtimeDepsService.importRuntime(specifier);
|
||||
}
|
||||
|
||||
async doSend(body: NotificationBody) {
|
||||
return await this.send(body);
|
||||
@@ -93,10 +108,16 @@ export abstract class BaseNotification implements INotification {
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
async onInstance() {}
|
||||
setCtx(ctx: NotificationContext) {
|
||||
async setCtx(ctx: NotificationContext) {
|
||||
this.ctx = ctx;
|
||||
this.http = ctx.http;
|
||||
this.logger = ctx.logger;
|
||||
if (!this.runtimeDepsService && this.ctx.serviceGetter) {
|
||||
this.runtimeDepsService = await this.ctx.serviceGetter.get("runtimeDepsService");
|
||||
}
|
||||
if (this.runtimeDepsService && this.ctx.define?.name) {
|
||||
await this.runtimeDepsService.ensureRuntimeDependencies(`notification:${this.ctx.define.name}`);
|
||||
}
|
||||
}
|
||||
setDefine = (define: NotificationDefine) => {
|
||||
this.define = define;
|
||||
|
||||
Reference in New Issue
Block a user