mirror of
https://github.com/certd/certd.git
synced 2026-04-15 05:00:52 +08:00
chore: plugin管理
This commit is contained in:
18
packages/ui/certd-server/db/migration/v10010__plugin.sql
Normal file
18
packages/ui/certd-server/db/migration/v10010__plugin.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE "pi_plugin"
|
||||
(
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"name" varchar(100) NOT NULL,
|
||||
"icon" varchar(100),
|
||||
"title" varchar(200),
|
||||
"desc" varchar(500),
|
||||
"group" varchar(100),
|
||||
"version" varchar(100),
|
||||
"setting" text,
|
||||
"sysSetting" text,
|
||||
"content" text,
|
||||
"type" strinng NOT NULL,
|
||||
"disabled" boolean NOT NULL,
|
||||
"create_time" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
|
||||
"update_time" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP)
|
||||
);
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
## sqlite与postgres不同点
|
||||
1.
|
||||
sl: AUTOINCREAMENT
|
||||
pg: GENERATED BY DEFAULT AS IDENTITY
|
||||
sqlite: AUTOINCREAMENT
|
||||
postgresql: GENERATED BY DEFAULT AS IDENTITY
|
||||
|
||||
2.
|
||||
datetime
|
||||
timestamp
|
||||
sqlite: datetime
|
||||
postgresql: timestamp
|
||||
|
||||
3.
|
||||
update sqlite_sequence set seq = 1000 where name = 'sys_role' ;
|
||||
select setval('sys_role_id_seq', 1000);
|
||||
sqlite: update sqlite_sequence set seq = 1000 where name = 'sys_role' ;
|
||||
postgresql: select setval('sys_role_id_seq', 1000);
|
||||
|
||||
4.
|
||||
"disabled" boolean DEFAULT (0)
|
||||
"disabled" boolean DEFAULT (false)
|
||||
sqlite: "disabled" boolean DEFAULT (0)
|
||||
postgresql: "disabled" boolean DEFAULT (false)
|
||||
|
||||
5.
|
||||
last_insert_rowid()
|
||||
LASTVAL()
|
||||
sqlite: last_insert_rowid()
|
||||
postgresql: LASTVAL()
|
||||
|
||||
6.
|
||||
sl: integer
|
||||
pg: bigint
|
||||
sqlite: integer
|
||||
postgresql: bigint
|
||||
|
||||
@@ -12,6 +12,10 @@ export class AccessController extends CrudController<AccessService> {
|
||||
@Inject()
|
||||
service: AccessService;
|
||||
|
||||
userId() {
|
||||
return this.getUserId();
|
||||
}
|
||||
|
||||
getService(): AccessService {
|
||||
return this.service;
|
||||
}
|
||||
@@ -19,36 +23,36 @@ export class AccessController extends CrudController<AccessService> {
|
||||
@Post('/page', { summary: Constants.per.authOnly })
|
||||
async page(@Body(ALL) body) {
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = this.getUserId();
|
||||
body.query.userId = this.userId();
|
||||
return await super.page(body);
|
||||
}
|
||||
|
||||
@Post('/list', { summary: Constants.per.authOnly })
|
||||
async list(@Body(ALL) body) {
|
||||
body.userId = this.getUserId();
|
||||
body.userId = this.userId();
|
||||
return super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { summary: Constants.per.authOnly })
|
||||
async add(@Body(ALL) bean) {
|
||||
bean.userId = this.getUserId();
|
||||
bean.userId = this.userId();
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { summary: Constants.per.authOnly })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.service.checkUserId(bean.id, this.getUserId());
|
||||
await this.service.checkUserId(bean.id, this.userId());
|
||||
return super.update(bean);
|
||||
}
|
||||
@Post('/info', { summary: Constants.per.authOnly })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.service.checkUserId(id, this.userId());
|
||||
return super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { summary: Constants.per.authOnly })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
await this.service.checkUserId(id, this.userId());
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { ALL, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { BaseController } from '@certd/lib-server';
|
||||
import { PluginService } from '../service/plugin-service.js';
|
||||
import { Constants } from '@certd/lib-server';
|
||||
|
||||
/**
|
||||
* 插件
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/pi/plugin')
|
||||
export class PluginController extends BaseController {
|
||||
@Inject()
|
||||
service: PluginService;
|
||||
|
||||
@Post('/list', { summary: Constants.per.authOnly })
|
||||
async list(@Query(ALL) query: any) {
|
||||
query.userId = this.getUserId();
|
||||
const list = this.service.getList();
|
||||
return this.ok(list);
|
||||
}
|
||||
|
||||
@Post('/groups', { summary: Constants.per.authOnly })
|
||||
async groups(@Query(ALL) query: any) {
|
||||
query.userId = this.getUserId();
|
||||
const group = this.service.getGroups();
|
||||
return this.ok(group);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import { UserService } from '../../sys/authority/service/user-service.js';
|
||||
import { AccessGetter } from './access-getter.js';
|
||||
import { CnameRecordService } from '../../cname/service/cname-record-service.js';
|
||||
import { CnameProxyService } from './cname-proxy-service.js';
|
||||
import { PluginConfigService } from './plugin-config-service.js';
|
||||
|
||||
const runningTasks: Map<string | number, Executor> = new Map();
|
||||
const freeCount = 10;
|
||||
@@ -45,6 +46,9 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
@Inject()
|
||||
historyLogService: HistoryLogService;
|
||||
|
||||
@Inject()
|
||||
pluginConfigService: PluginConfigService;
|
||||
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
|
||||
@@ -356,6 +360,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
onChanged,
|
||||
accessService: accessGetter,
|
||||
cnameProxyService,
|
||||
pluginConfigService: this.pluginConfigService,
|
||||
storage: new DbStorage(userId, this.storageService),
|
||||
emailService: this.emailService,
|
||||
fileRootDir: this.certdConfig.fileRootDir,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { IPluginConfigService } from '@certd/pipeline';
|
||||
|
||||
/**
|
||||
* 授权
|
||||
*/
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
export class PluginConfigService implements IPluginConfigService {
|
||||
getPluginConfig(pluginName: string) {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { pluginGroups, pluginRegistry } from '@certd/pipeline';
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
export class PluginService {
|
||||
export class BuiltInPluginService {
|
||||
getList() {
|
||||
const collection = pluginRegistry.storage;
|
||||
const list = [];
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user