mirror of https://github.com/certd/certd
fix: 修复导入在线插件不生效的bug
parent
76b19a4980
commit
fcf8309c23
|
@ -1,39 +1,39 @@
|
||||||
export * from './util.request.js';
|
export * from "./util.request.js";
|
||||||
export * from './util.env.js';
|
export * from "./util.env.js";
|
||||||
export * from './util.log.js';
|
export * from "./util.log.js";
|
||||||
export * from './util.file.js';
|
export * from "./util.file.js";
|
||||||
export * from './util.sp.js';
|
export * from "./util.sp.js";
|
||||||
export * from './util.promise.js';
|
export * from "./util.promise.js";
|
||||||
export * from './util.hash.js';
|
export * from "./util.hash.js";
|
||||||
export * from './util.merge.js';
|
export * from "./util.merge.js";
|
||||||
export * from './util.cache.js';
|
export * from "./util.cache.js";
|
||||||
export * from './util.string.js';
|
export * from "./util.string.js";
|
||||||
export * from './util.lock.js';
|
export * from "./util.lock.js";
|
||||||
export * from './util.mitter.js';
|
export * from "./util.mitter.js";
|
||||||
export * from './util.id.js';
|
export * from "./util.id.js";
|
||||||
export * from './util.domain.js';
|
export * from "./util.domain.js";
|
||||||
export * from './util.amount.js';
|
export * from "./util.amount.js";
|
||||||
import { stringUtils } from './util.string.js';
|
import { stringUtils } from "./util.string.js";
|
||||||
import sleep from './util.sleep.js';
|
import sleep from "./util.sleep.js";
|
||||||
import { http, download } from './util.request.js';
|
import { http, download } from "./util.request.js";
|
||||||
|
|
||||||
import { mergeUtils } from './util.merge.js';
|
import { mergeUtils } from "./util.merge.js";
|
||||||
import { sp } from './util.sp.js';
|
import { sp } from "./util.sp.js";
|
||||||
import { hashUtils } from './util.hash.js';
|
import { hashUtils } from "./util.hash.js";
|
||||||
import { promises } from './util.promise.js';
|
import { promises } from "./util.promise.js";
|
||||||
import { fileUtils } from './util.file.js';
|
import { fileUtils } from "./util.file.js";
|
||||||
import * as _ from 'lodash-es';
|
import * as _ from "lodash-es";
|
||||||
import { cache } from './util.cache.js';
|
import { cache } from "./util.cache.js";
|
||||||
import dayjs from 'dayjs';
|
import dayjs from "dayjs";
|
||||||
import { domainUtils } from './util.domain.js';
|
import { domainUtils } from "./util.domain.js";
|
||||||
import { optionsUtils } from './util.options.js';
|
import { optionsUtils } from "./util.options.js";
|
||||||
import { amountUtils } from './util.amount.js';
|
import { amountUtils } from "./util.amount.js";
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from "nanoid";
|
||||||
import * as id from './util.id.js';
|
import * as id from "./util.id.js";
|
||||||
import { locker } from './util.lock.js';
|
import { locker } from "./util.lock.js";
|
||||||
import { mitter } from './util.mitter.js';
|
import { mitter } from "./util.mitter.js";
|
||||||
|
|
||||||
import * as request from './util.request.js';
|
import * as request from "./util.request.js";
|
||||||
export const utils = {
|
export const utils = {
|
||||||
sleep,
|
sleep,
|
||||||
http,
|
http,
|
||||||
|
|
|
@ -14,9 +14,13 @@ function hmacSha256(data: string, digest: BinaryToTextEncoding = "base64") {
|
||||||
function base64(data: string) {
|
function base64(data: string) {
|
||||||
return Buffer.from(data).toString("base64");
|
return Buffer.from(data).toString("base64");
|
||||||
}
|
}
|
||||||
|
function base64Decode(data: string) {
|
||||||
|
return Buffer.from(data, "base64").toString("utf8");
|
||||||
|
}
|
||||||
export const hashUtils = {
|
export const hashUtils = {
|
||||||
md5,
|
md5,
|
||||||
sha256,
|
sha256,
|
||||||
base64,
|
base64,
|
||||||
|
base64Decode,
|
||||||
hmacSha256,
|
hmacSha256,
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,6 +48,11 @@ export class Registry<T = any> {
|
||||||
logger.info(`注册插件:${this.type}:${key}`);
|
logger.info(`注册插件:${this.type}:${key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unRegister(key: string) {
|
||||||
|
delete this.storage[key];
|
||||||
|
logger.info(`反注册插件:${this.type}:${key}`);
|
||||||
|
}
|
||||||
|
|
||||||
get(name: string): RegistryItem<T> {
|
get(name: string): RegistryItem<T> {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
throw new Error("插件名称不能为空");
|
throw new Error("插件名称不能为空");
|
||||||
|
|
|
@ -57,12 +57,12 @@ export class PluginController extends CrudController<PluginService> {
|
||||||
|
|
||||||
@Post('/delete', { summary: 'sys:settings:edit' })
|
@Post('/delete', { summary: 'sys:settings:edit' })
|
||||||
async delete(@Query('id') id: number) {
|
async delete(@Query('id') id: number) {
|
||||||
return super.delete(id);
|
return super.deleteByIds([id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/deleteByIds', { summary: 'sys:settings:edit' })
|
@Post('/deleteByIds', { summary: 'sys:settings:edit' })
|
||||||
async deleteByIds(@Body('ids') ids: number[]) {
|
async deleteByIds(@Body('ids') ids: number[]) {
|
||||||
const res = await this.service.delete(ids);
|
const res = await this.service.deleteByIds(ids);
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,10 +193,49 @@ export class PluginService extends BaseService<PluginEntity> {
|
||||||
throw new Error(`插件类型${param.pluginType}不支持`);
|
throw new Error(`插件类型${param.pluginType}不支持`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await super.add({
|
const res= await super.add({
|
||||||
...param,
|
...param,
|
||||||
...plugin
|
...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) {
|
async update(param: any) {
|
||||||
|
@ -211,7 +250,11 @@ export class PluginService extends BaseService<PluginEntity> {
|
||||||
throw new Error(`插件${param.author}/${param.name}已存在`);
|
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) {
|
async compile(code: string) {
|
||||||
|
@ -420,4 +463,12 @@ export class PluginService extends BaseService<PluginEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async deleteByIds(ids:any[]){
|
||||||
|
await super.delete(ids);
|
||||||
|
for (const id of ids) {
|
||||||
|
await this.unRegisterById(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue