perf: 部署支持1Panel

This commit is contained in:
xiaojunnuo
2024-09-27 02:15:41 +08:00
parent 3f21a49988
commit d047234d98
20 changed files with 342 additions and 95 deletions
@@ -1,36 +1,110 @@
import { ALL, Body, Controller, Post, Provide } from '@midwayjs/core';
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { Constants } from '../../../basic/constants.js';
import { accessRegistry, http, logger, PluginRequest, RequestHandleContext } from '@certd/pipeline';
import { merge } from 'lodash-es';
import {
accessRegistry,
AccessRequestHandleContext,
AccessRequestHandleReq,
http,
ITaskPlugin,
logger,
mergeUtils,
pluginRegistry,
PluginRequestHandleReq,
TaskInstanceContext,
utils,
} from '@certd/pipeline';
import { BaseController } from '../../../basic/base-controller.js';
import { AccessService } from '../service/access-service.js';
import { EmailService } from '../../basic/service/email-service.js';
@Provide()
@Controller('/api/pi/handle')
export class HandleController extends BaseController {
@Post('/', { summary: Constants.per.authOnly })
async request(@Body(ALL) body: PluginRequest) {
const type = body.type;
if (type === 'access') {
const accessItem = accessRegistry.get(body.typeName);
const accessCls = accessItem.target;
if (accessCls == null) {
throw new Error(`access ${body.typeName} not found`);
}
//实例化access
//@ts-ignore
const access = new accessCls();
//注入input
merge(access, body.input);
const ctx: RequestHandleContext = {
http: http,
logger: logger,
};
const res = await access.onRequest(body, ctx);
@Inject()
accessService: AccessService;
return this.ok(res);
} else if (type === 'plugin') {
throw new Error(`plugin:${body.typeName} not support`);
} else {
throw new Error(`type:${type} not support`);
@Inject()
emailService: EmailService;
@Post('/access', { summary: Constants.per.authOnly })
async accessRequest(@Body(ALL) body: AccessRequestHandleReq) {
const accessItem = accessRegistry.get(body.typeName);
const accessCls = accessItem.target;
if (accessCls == null) {
throw new Error(`access ${body.typeName} not found`);
}
//实例化access
//@ts-ignore
const access = new accessCls();
let isNew = true;
if (body.input.id > 0) {
const oldEntity = await this.accessService.info(body.input.id);
if (!oldEntity) {
isNew = false;
const param = {
type: body.typeName,
setting: JSON.stringify(body.input.access),
};
this.accessService.encryptSetting(param, oldEntity);
body.input.access = JSON.parse(param.setting);
}
}
if (isNew) {
mergeUtils.merge(access, body.input.access);
}
const ctx: AccessRequestHandleContext = {
http: http,
logger: logger,
utils,
};
const res = await access.onRequest(body, ctx);
return this.ok(res);
}
@Post('/plugin', { summary: Constants.per.authOnly })
async pluginRequest(@Body(ALL) body: PluginRequestHandleReq) {
const pluginDefine = pluginRegistry.get(body.typeName);
const pluginCls = pluginDefine.target;
if (pluginCls == null) {
throw new Error(`plugin ${body.typeName} not found`);
}
//实例化access
//@ts-ignore
const plugin: PluginRequestHandler = new pluginCls();
//@ts-ignore
const instance = plugin as ITaskPlugin;
//@ts-ignore
const taskCtx: TaskInstanceContext = {
pipeline: undefined,
step: undefined,
lastStatus: undefined,
http,
logger: logger,
inputChanged: true,
accessService: this.accessService,
emailService: this.emailService,
pipelineContext: undefined,
userContext: undefined,
fileStore: undefined,
signal: undefined,
// pipelineContext: this.pipelineContext,
// userContext: this.contextFactory.getContext('user', this.options.userId),
// fileStore: new FileStore({
// scope: this.pipeline.id,
// parent: this.runtime.id,
// rootDir: this.options.fileRootDir,
// }),
// signal: this.abort.signal,
utils,
};
instance.setCtx(taskCtx);
mergeUtils.merge(plugin, body.input);
await instance.onInstance();
const res = await plugin.onRequest(body);
return this.ok(res);
}
}