mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2024-11-01 22:20:30 +08:00
优化插件校验
This commit is contained in:
parent
bb5d19841c
commit
4c9ae93d21
@ -1,5 +1,5 @@
|
|||||||
import { BaseEntity } from '@cool-midway/core';
|
import { BaseEntity } from '@cool-midway/core';
|
||||||
import { Column, Entity, DataSource } from 'typeorm';
|
import { Column, Entity, DataSource, Index } from 'typeorm';
|
||||||
|
|
||||||
console.log(DataSource);
|
console.log(DataSource);
|
||||||
|
|
||||||
@ -14,6 +14,7 @@ export class PluginInfoEntity extends BaseEntity {
|
|||||||
@Column({ comment: '简介' })
|
@Column({ comment: '简介' })
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
|
@Index()
|
||||||
@Column({ comment: 'Key名' })
|
@Column({ comment: 'Key名' })
|
||||||
keyName: string;
|
keyName: string;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { App, Inject, Provide } from '@midwayjs/decorator';
|
import { App, Inject, Provide } from '@midwayjs/decorator';
|
||||||
import { BaseService, CoolCommException } from '@cool-midway/core';
|
import { BaseService, CoolCommException } from '@cool-midway/core';
|
||||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||||
import { Not, Repository } from 'typeorm';
|
import { Equal, Not, Repository } from 'typeorm';
|
||||||
import { PluginInfoEntity } from '../entity/info';
|
import { PluginInfoEntity } from '../entity/info';
|
||||||
import { IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
import { IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@ -59,6 +59,7 @@ export class PluginService extends BaseService {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async invoke(key: string, method: string, ...params) {
|
async invoke(key: string, method: string, ...params) {
|
||||||
|
await this.checkStatus(key);
|
||||||
// 实例化
|
// 实例化
|
||||||
const instance = new (await this.pluginCenterService.plugins.get(key))();
|
const instance = new (await this.pluginCenterService.plugins.get(key))();
|
||||||
await instance.init(
|
await instance.init(
|
||||||
@ -69,6 +70,20 @@ export class PluginService extends BaseService {
|
|||||||
return await instance[method](...params);
|
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
|
* @param filePath
|
||||||
|
Loading…
Reference in New Issue
Block a user