chore: plugin管理

This commit is contained in:
xiaojunnuo
2024-10-13 01:27:08 +08:00
parent 6f8fe62087
commit ccfe72a0d9
29 changed files with 729 additions and 163 deletions
@@ -0,0 +1,62 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { AccessService } from '../../pipeline/service/access-service.js';
import { AccessController } from '../../pipeline/controller/access-controller.js';
import { checkComm } from '@certd/pipeline';
/**
* 授权
*/
@Provide()
@Controller('/api/sys/access')
export class SysAccessController extends AccessController {
@Inject()
service2: AccessService;
getService(): AccessService {
return this.service2;
}
userId() {
checkComm();
return 0;
}
@Post('/page', { summary: 'sys:settings:view' })
async page(@Body(ALL) body: any) {
return await await super.page(body);
}
@Post('/list', { summary: 'sys:settings:view' })
async list(@Body(ALL) body: any) {
return await super.list(body);
}
@Post('/add', { summary: 'sys:settings:edit' })
async add(@Body(ALL) bean: any) {
return await super.add(bean);
}
@Post('/update', { summary: 'sys:settings:edit' })
async update(@Body(ALL) bean: any) {
return await super.update(bean);
}
@Post('/info', { summary: 'sys:settings:view' })
async info(@Query('id') id: number) {
return await super.info(id);
}
@Post('/delete', { summary: 'sys:settings:edit' })
async delete(@Query('id') id: number) {
return await super.delete(id);
}
@Post('/define', { summary: 'sys:settings:view' })
async define(@Query('type') type: string) {
return await super.define(type);
}
@Post('/accessTypeDict', { summary: 'sys:settings:view' })
async getAccessTypeDict() {
return await super.getAccessTypeDict();
}
}
@@ -0,0 +1,68 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { merge } from 'lodash-es';
import { CrudController } from '@certd/lib-server';
import { PluginService } from '../service/plugin-service.js';
import { checkComm } from '@certd/pipeline';
/**
* 插件
*/
@Provide()
@Controller('/api/sys/plugin')
export class PluginController extends CrudController<PluginService> {
@Inject()
service: PluginService;
getService() {
checkComm();
return this.service;
}
@Post('/page', { summary: 'sys:settings:view' })
async page(@Body(ALL) body: any) {
body.query = body.query ?? {};
return await super.page(body);
}
@Post('/list', { summary: 'sys:settings:view' })
async list(@Body(ALL) body: any) {
return super.list(body);
}
@Post('/add', { summary: 'sys:settings:edit' })
async add(@Body(ALL) bean: any) {
const def: any = {
isDefault: false,
disabled: false,
};
merge(bean, def);
return super.add(bean);
}
@Post('/update', { summary: 'sys:settings:edit' })
async update(@Body(ALL) bean: any) {
return super.update(bean);
}
@Post('/info', { summary: 'sys:settings:view' })
async info(@Query('id') id: number) {
return super.info(id);
}
@Post('/delete', { summary: 'sys:settings:edit' })
async delete(@Query('id') id: number) {
return super.delete(id);
}
@Post('/deleteByIds', { summary: 'sys:settings:edit' })
async deleteByIds(@Body(ALL) body: { ids: number[] }) {
const res = await this.service.delete(body.ids);
return this.ok(res);
}
@Post('/setDisabled', { summary: 'sys:settings:edit' })
async setDisabled(@Body('id') id: number, @Body('disabled') disabled: boolean) {
await this.service.setDisabled(id, disabled);
return this.ok();
}
}
@@ -0,0 +1,50 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity('pi_plugin')
export class PluginEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'name', comment: 'Key' })
name: string;
@Column({ name: 'icon', comment: '图标' })
icon: string;
@Column({ name: 'title', comment: '标题' })
title: string;
@Column({ name: 'group', comment: '分组' })
group: string;
@Column({ name: 'desc', comment: '描述' })
desc: string;
@Column({ comment: '配置', length: 40960 })
setting: string;
@Column({ comment: '系统配置', length: 40960 })
sysSetting: string;
@Column({ comment: '脚本', length: 40960 })
content: string;
@Column({ comment: '类型', length: 100, nullable: true })
type: string; // builtIn | custom
@Column({ comment: '启用/禁用', default: false })
disabled: boolean;
@Column({
name: 'create_time',
comment: '创建时间',
default: () => 'CURRENT_TIMESTAMP',
})
createTime: Date;
@Column({
name: 'update_time',
comment: '修改时间',
default: () => 'CURRENT_TIMESTAMP',
})
updateTime: Date;
}
@@ -0,0 +1,23 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { BaseService } from '@certd/lib-server';
import { PluginEntity } from '../entity/plugin.js';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { checkComm } from '@certd/pipeline';
@Provide()
@Scope(ScopeEnum.Singleton)
export class PluginService extends BaseService<PluginEntity> {
@InjectEntityModel(PluginEntity)
repository: Repository<PluginEntity>;
//@ts-ignore
getRepository() {
checkComm();
return this.repository;
}
async setDisabled(id: number, disabled: boolean) {
await this.repository.update({ id }, { disabled });
}
}