diff --git a/src/modules/plugin/entity/info.ts b/src/modules/plugin/entity/info.ts index 750e5d9..fddebc8 100644 --- a/src/modules/plugin/entity/info.ts +++ b/src/modules/plugin/entity/info.ts @@ -1,5 +1,5 @@ import { BaseEntity } from '@cool-midway/core'; -import { Column, Entity, DataSource } from 'typeorm'; +import { Column, Entity, DataSource, Index } from 'typeorm'; console.log(DataSource); @@ -14,6 +14,7 @@ export class PluginInfoEntity extends BaseEntity { @Column({ comment: '简介' }) description: string; + @Index() @Column({ comment: 'Key名' }) keyName: string; diff --git a/src/modules/plugin/service/info.ts b/src/modules/plugin/service/info.ts index 3730ada..f4e557c 100644 --- a/src/modules/plugin/service/info.ts +++ b/src/modules/plugin/service/info.ts @@ -1,7 +1,7 @@ import { App, Inject, Provide } from '@midwayjs/decorator'; import { BaseService, CoolCommException } from '@cool-midway/core'; import { InjectEntityModel } from '@midwayjs/typeorm'; -import { Not, Repository } from 'typeorm'; +import { Equal, Not, Repository } from 'typeorm'; import { PluginInfoEntity } from '../entity/info'; import { IMidwayApplication, IMidwayContext } from '@midwayjs/core'; import * as _ from 'lodash'; @@ -59,6 +59,7 @@ export class PluginService extends BaseService { * @returns */ async invoke(key: string, method: string, ...params) { + await this.checkStatus(key); // 实例化 const instance = new (await this.pluginCenterService.plugins.get(key))(); await instance.init( @@ -69,6 +70,20 @@ export class PluginService extends BaseService { return await instance[method](...params); } + /** + * 检查状态 + * @param key + */ + async checkStatus(key: string) { + const info = await this.pluginInfoEntity.findOneBy({ + keyName: Equal(key), + status: 0, + }); + if (info) { + throw new CoolCommException('插件不存在或已禁用'); + } + } + /** * 检查 * @param filePath