mirror of
https://github.com/certd/certd.git
synced 2026-06-20 08:37:31 +08:00
feat: 通过插件配置懒加载依赖,动态加载第三方依赖包,精简安装镜像大小
This commit is contained in:
@@ -4,6 +4,8 @@ import { IAccess, IAccessService, IServiceGetter, PageRes, PageSearch, Registrab
|
||||
export type DnsProviderDefine = Registrable & {
|
||||
accessType: string;
|
||||
icon?: string;
|
||||
dependPlugins?: Record<string, string>;
|
||||
dependPackages?: Record<string, string>;
|
||||
};
|
||||
|
||||
export type CreateRecordOptions = {
|
||||
@@ -27,6 +29,7 @@ export type DnsProviderContext = {
|
||||
domainParser: IDomainParser;
|
||||
serviceGetter: IServiceGetter;
|
||||
accessGetter?: IAccessService;
|
||||
define?: DnsProviderDefine;
|
||||
};
|
||||
|
||||
export type DomainRecord = {
|
||||
@@ -61,7 +64,7 @@ export interface IDnsProvider<T = any> {
|
||||
|
||||
removeRecord(options: RemoveRecordOptions<T>): Promise<void>;
|
||||
|
||||
setCtx(ctx: DnsProviderContext): void;
|
||||
setCtx(ctx: DnsProviderContext): Promise<void>;
|
||||
|
||||
//中文域名是否需要punycode转码,如果返回True,则使用punycode来添加解析记录,否则使用中文域名添加解析记录
|
||||
usePunyCode(): boolean;
|
||||
|
||||
@@ -7,6 +7,17 @@ export abstract class AbstractDnsProvider<T = any> implements IDnsProvider<T> {
|
||||
ctx!: DnsProviderContext;
|
||||
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);
|
||||
}
|
||||
|
||||
usePunyCode(): boolean {
|
||||
//是否使用punycode来添加解析记录
|
||||
@@ -30,10 +41,16 @@ export abstract class AbstractDnsProvider<T = any> implements IDnsProvider<T> {
|
||||
return punycode.toUnicode(domain);
|
||||
}
|
||||
|
||||
setCtx(ctx: DnsProviderContext) {
|
||||
async setCtx(ctx: DnsProviderContext) {
|
||||
this.ctx = ctx;
|
||||
this.logger = ctx.logger;
|
||||
this.http = ctx.http;
|
||||
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(`dnsProvider:${this.ctx.define.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
async parseDomain(fullDomain: string) {
|
||||
@@ -68,9 +85,10 @@ export async function createDnsProvider(opts: { dnsProviderType: string; context
|
||||
const accessGetter: IAccessService = await context.serviceGetter.get("accessService");
|
||||
context.accessGetter = accessGetter;
|
||||
}
|
||||
context.define = dnsProviderDefine;
|
||||
// @ts-ignore
|
||||
const dnsProvider: IDnsProvider = new DnsProviderClass();
|
||||
dnsProvider.setCtx(context);
|
||||
await dnsProvider.setCtx(context);
|
||||
await dnsProvider.onInstance();
|
||||
return dnsProvider;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user