mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2024-11-01 14:10:29 +08:00
优化插件校验
This commit is contained in:
parent
bb5d19841c
commit
4c9ae93d21
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user