diff --git a/packages/core/basic/src/utils/index.ts b/packages/core/basic/src/utils/index.ts index 642fa9bc..94b2109f 100644 --- a/packages/core/basic/src/utils/index.ts +++ b/packages/core/basic/src/utils/index.ts @@ -1,39 +1,39 @@ -export * from './util.request.js'; -export * from './util.env.js'; -export * from './util.log.js'; -export * from './util.file.js'; -export * from './util.sp.js'; -export * from './util.promise.js'; -export * from './util.hash.js'; -export * from './util.merge.js'; -export * from './util.cache.js'; -export * from './util.string.js'; -export * from './util.lock.js'; -export * from './util.mitter.js'; -export * from './util.id.js'; -export * from './util.domain.js'; -export * from './util.amount.js'; -import { stringUtils } from './util.string.js'; -import sleep from './util.sleep.js'; -import { http, download } from './util.request.js'; +export * from "./util.request.js"; +export * from "./util.env.js"; +export * from "./util.log.js"; +export * from "./util.file.js"; +export * from "./util.sp.js"; +export * from "./util.promise.js"; +export * from "./util.hash.js"; +export * from "./util.merge.js"; +export * from "./util.cache.js"; +export * from "./util.string.js"; +export * from "./util.lock.js"; +export * from "./util.mitter.js"; +export * from "./util.id.js"; +export * from "./util.domain.js"; +export * from "./util.amount.js"; +import { stringUtils } from "./util.string.js"; +import sleep from "./util.sleep.js"; +import { http, download } from "./util.request.js"; -import { mergeUtils } from './util.merge.js'; -import { sp } from './util.sp.js'; -import { hashUtils } from './util.hash.js'; -import { promises } from './util.promise.js'; -import { fileUtils } from './util.file.js'; -import * as _ from 'lodash-es'; -import { cache } from './util.cache.js'; -import dayjs from 'dayjs'; -import { domainUtils } from './util.domain.js'; -import { optionsUtils } from './util.options.js'; -import { amountUtils } from './util.amount.js'; -import { nanoid } from 'nanoid'; -import * as id from './util.id.js'; -import { locker } from './util.lock.js'; -import { mitter } from './util.mitter.js'; +import { mergeUtils } from "./util.merge.js"; +import { sp } from "./util.sp.js"; +import { hashUtils } from "./util.hash.js"; +import { promises } from "./util.promise.js"; +import { fileUtils } from "./util.file.js"; +import * as _ from "lodash-es"; +import { cache } from "./util.cache.js"; +import dayjs from "dayjs"; +import { domainUtils } from "./util.domain.js"; +import { optionsUtils } from "./util.options.js"; +import { amountUtils } from "./util.amount.js"; +import { nanoid } from "nanoid"; +import * as id from "./util.id.js"; +import { locker } from "./util.lock.js"; +import { mitter } from "./util.mitter.js"; -import * as request from './util.request.js'; +import * as request from "./util.request.js"; export const utils = { sleep, http, diff --git a/packages/core/basic/src/utils/util.hash.ts b/packages/core/basic/src/utils/util.hash.ts index 87f6a0e8..303ffa1d 100644 --- a/packages/core/basic/src/utils/util.hash.ts +++ b/packages/core/basic/src/utils/util.hash.ts @@ -14,9 +14,13 @@ function hmacSha256(data: string, digest: BinaryToTextEncoding = "base64") { function base64(data: string) { return Buffer.from(data).toString("base64"); } +function base64Decode(data: string) { + return Buffer.from(data, "base64").toString("utf8"); +} export const hashUtils = { md5, sha256, base64, + base64Decode, hmacSha256, }; diff --git a/packages/core/pipeline/src/registry/registry.ts b/packages/core/pipeline/src/registry/registry.ts index 9abc85d3..b466bcc9 100644 --- a/packages/core/pipeline/src/registry/registry.ts +++ b/packages/core/pipeline/src/registry/registry.ts @@ -48,6 +48,11 @@ export class Registry { logger.info(`注册插件:${this.type}:${key}`); } + unRegister(key: string) { + delete this.storage[key]; + logger.info(`反注册插件:${this.type}:${key}`); + } + get(name: string): RegistryItem { if (!name) { throw new Error("插件名称不能为空"); diff --git a/packages/ui/certd-server/src/controller/sys/plugin/plugin-controller.ts b/packages/ui/certd-server/src/controller/sys/plugin/plugin-controller.ts index a0bd13f4..6ff73443 100644 --- a/packages/ui/certd-server/src/controller/sys/plugin/plugin-controller.ts +++ b/packages/ui/certd-server/src/controller/sys/plugin/plugin-controller.ts @@ -57,12 +57,12 @@ export class PluginController extends CrudController { @Post('/delete', { summary: 'sys:settings:edit' }) async delete(@Query('id') id: number) { - return super.delete(id); + return super.deleteByIds([id]); } @Post('/deleteByIds', { summary: 'sys:settings:edit' }) async deleteByIds(@Body('ids') ids: number[]) { - const res = await this.service.delete(ids); + const res = await this.service.deleteByIds(ids); return this.ok(res); } diff --git a/packages/ui/certd-server/src/modules/plugin/service/plugin-service.ts b/packages/ui/certd-server/src/modules/plugin/service/plugin-service.ts index c3c94a07..2793ebfc 100644 --- a/packages/ui/certd-server/src/modules/plugin/service/plugin-service.ts +++ b/packages/ui/certd-server/src/modules/plugin/service/plugin-service.ts @@ -193,10 +193,49 @@ export class PluginService extends BaseService { throw new Error(`插件类型${param.pluginType}不支持`); } - return await super.add({ + const res= await super.add({ ...param, ...plugin }); + + await this.registerById(res.id); + return res + } + + async registerById(id: any) { + const item = await this.info(id); + if (!item) { + return; + } + if(item.type === "builtIn"){ + return; + } + await this.registerPlugin(item); + } + + async unRegisterById(id: any){ + const item = await this.info(id); + if (!item) { + return; + } + if (item.type === "builtIn") { + return; + } + let name = item.name; + if (item.author){ + name = `${item.author}/${item.name}` + } + if (item.pluginType === "access"){ + accessRegistry.unRegister(name) + }else if (item.pluginType === "deploy"){ + pluginRegistry.unRegister(name) + }else if (item.pluginType === "dnsProvider"){ + dnsProviderRegistry.unRegister(name) + }else if (item.pluginType === "notification"){ + notificationRegistry.unRegister(name) + }else{ + logger.warn(`不支持的插件类型:${item.pluginType}`) + } } async update(param: any) { @@ -211,7 +250,11 @@ export class PluginService extends BaseService { throw new Error(`插件${param.author}/${param.name}已存在`); } - return await super.update(param); + + const res= await super.update(param); + + await this.registerById(param.id); + return res } async compile(code: string) { @@ -420,4 +463,12 @@ export class PluginService extends BaseService { } + async deleteByIds(ids:any[]){ + await super.delete(ids); + for (const id of ids) { + await this.unRegisterById(id) + } + } + + }