mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
perf: 部署支持1Panel
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<script setup lang="ts">
|
||||
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
|
||||
import { ref, watch } from "vue";
|
||||
|
||||
const props = defineProps<
|
||||
{
|
||||
watches: string[];
|
||||
} & ComponentPropsType
|
||||
>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
"update:value": any;
|
||||
}>();
|
||||
|
||||
const optionsRef = ref([]);
|
||||
const getOptions = async () => {
|
||||
return await doRequest({
|
||||
type: props.type,
|
||||
typeName: props.typeName,
|
||||
action: props.action,
|
||||
input: props.form
|
||||
});
|
||||
};
|
||||
|
||||
watch(
|
||||
() => {
|
||||
const values = [];
|
||||
for (const item of props.watches) {
|
||||
values.push(props.form[item]);
|
||||
}
|
||||
return {
|
||||
form: props.form,
|
||||
watched: values
|
||||
};
|
||||
},
|
||||
async () => {
|
||||
optionsRef.value = await getOptions();
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-select class="remote-select" :options="optionsRef" :value="value" @update:value="emit('update:value', $event)" />
|
||||
</template>
|
||||
|
||||
<style lang="less"></style>
|
||||
@@ -1,6 +1,8 @@
|
||||
import PiSynologyIdDeviceGetter from "./synology/device-id-getter.vue";
|
||||
import SynologyIdDeviceGetter from "./synology/device-id-getter.vue";
|
||||
import RemoteSelect from "./common/remote-select.vue";
|
||||
export default {
|
||||
install(app: any) {
|
||||
app.component("PiSynologyDeviceIdGetter", PiSynologyIdDeviceGetter);
|
||||
app.component("SynologyDeviceIdGetter", SynologyIdDeviceGetter);
|
||||
app.component("RemoteSelect", RemoteSelect);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { request } from "/@/api/service";
|
||||
export type ComponentPropsType = {
|
||||
type: string;
|
||||
typeName: string;
|
||||
action: string;
|
||||
form: any;
|
||||
value?: any;
|
||||
};
|
||||
export type RequestHandleReq<T = any> = {
|
||||
type: strin;
|
||||
typeName: string;
|
||||
action: string;
|
||||
data: any;
|
||||
input: T;
|
||||
};
|
||||
|
||||
export async function doRequest(req: RequestHandleReq) {
|
||||
const url = req.type === "access" ? "/pi/handle/access" : "/pi/handle/plugin";
|
||||
const { typeName, action, data, input } = req;
|
||||
const res = await request({
|
||||
url,
|
||||
method: "post",
|
||||
data: {
|
||||
typeName,
|
||||
action,
|
||||
data,
|
||||
input
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
@@ -11,15 +11,10 @@
|
||||
|
||||
<script lang="tsx" setup>
|
||||
import { defineProps, ref, useAttrs } from "vue";
|
||||
import { request } from "/@/api/service";
|
||||
import { Modal } from "ant-design-vue";
|
||||
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
|
||||
|
||||
const props = defineProps<{
|
||||
type: string;
|
||||
typeName: string;
|
||||
form: any;
|
||||
value?: any;
|
||||
}>();
|
||||
const props = defineProps<ComponentPropsType>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
"update:value": any;
|
||||
@@ -29,24 +24,15 @@ const attrs = useAttrs();
|
||||
|
||||
const otpCodeRef = ref("");
|
||||
|
||||
async function doRequest(action: string, data: any) {
|
||||
const res = await request({
|
||||
url: "/pi/handle",
|
||||
method: "post",
|
||||
data: {
|
||||
type: props.type,
|
||||
typeName: props.typeName,
|
||||
action,
|
||||
data: data,
|
||||
input: props.form.access
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
async function loginWithOTPCode(otpCode: string) {
|
||||
return await doRequest("LoginWithOPTCode", {
|
||||
otpCode
|
||||
return await doRequest({
|
||||
type: props.type,
|
||||
typeName: props.typeName,
|
||||
action: "LoginWithOPTCode",
|
||||
data: {
|
||||
otpCode
|
||||
},
|
||||
form: props.form
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
import _ from "lodash-es";
|
||||
import { compute } from "@fast-crud/fast-crud";
|
||||
import { asyncCompute, compute } from "@fast-crud/fast-crud";
|
||||
import { computed } from "vue";
|
||||
|
||||
export type MergeScriptContext = {
|
||||
compute: typeof compute;
|
||||
asyncCompute: typeof asyncCompute;
|
||||
computed: typeof computed;
|
||||
};
|
||||
|
||||
export function useReference(formItem: any) {
|
||||
if (formItem.reference) {
|
||||
for (const reference of formItem.reference) {
|
||||
_.set(
|
||||
formItem,
|
||||
reference.dest,
|
||||
compute<any>((scope) => {
|
||||
return _.get(scope, reference.src);
|
||||
})
|
||||
);
|
||||
}
|
||||
delete formItem.reference;
|
||||
}
|
||||
|
||||
if (formItem.mergeScript) {
|
||||
const ctx = {
|
||||
compute
|
||||
compute,
|
||||
asyncCompute,
|
||||
computed
|
||||
};
|
||||
const script = formItem.mergeScript;
|
||||
const func = new Function("ctx", script);
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
"kubernetes-client": "^9.0.0",
|
||||
"lodash-es": "^4.17.21",
|
||||
"log4js": "^6.7.1",
|
||||
"lru-cache": "^10.0.0",
|
||||
"lru-cache": "^10.2.0",
|
||||
"md5": "^2.3.0",
|
||||
"mwtsc": "^1.4.0",
|
||||
"nanoid": "^4.0.0",
|
||||
@@ -95,7 +95,7 @@
|
||||
"mwts": "^1.3.0",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "~5.1.0"
|
||||
"typescript": "^5.4.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"compileOnSave": true,
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node16",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
|
||||
Reference in New Issue
Block a user