From 4c9ae93d21281ec70998f1c7066170d1a3010568 Mon Sep 17 00:00:00 2001 From: cool Date: Tue, 30 Jan 2024 16:02:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8F=92=E4=BB=B6=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/plugin/entity/info.ts | 3 ++- src/modules/plugin/service/info.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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