mirror of https://github.com/certd/certd
perf: 通知渠道支持测试按钮
parent
3af6d96e6e
commit
b54ae272eb
|
@ -41,6 +41,10 @@ export type AccessContext = {
|
|||
export abstract class BaseAccess implements IAccess {
|
||||
ctx!: AccessContext;
|
||||
|
||||
setCtx(ctx: AccessContext) {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
async onRequest(req: AccessRequestHandleReq) {
|
||||
if (!req.action) {
|
||||
throw new Error("action is required");
|
||||
|
|
|
@ -56,6 +56,6 @@ export function newAccess(type: string, input: any, ctx?: AccessContext) {
|
|||
utils,
|
||||
};
|
||||
}
|
||||
access.ctx = ctx;
|
||||
access.setCtx(ctx);
|
||||
return access;
|
||||
}
|
||||
|
|
|
@ -93,4 +93,19 @@ export abstract class BaseNotification implements INotification {
|
|||
}
|
||||
throw new Error(`action ${req.action} not found`);
|
||||
}
|
||||
|
||||
async onTestRequest() {
|
||||
await this.send({
|
||||
userId: 0,
|
||||
title: "测试通知",
|
||||
content: "测试通知",
|
||||
pipeline: {
|
||||
id: 1,
|
||||
title: "测试流水线",
|
||||
} as any,
|
||||
pipelineId: 1,
|
||||
historyId: 1,
|
||||
url: "http://www.baidu.com",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,13 +44,13 @@ export function newNotification(type: string, input: any, ctx: NotificationConte
|
|||
throw new Error(`notification ${type} not found`);
|
||||
}
|
||||
// @ts-ignore
|
||||
const access = new register.target();
|
||||
const plugin = new register.target();
|
||||
for (const key in input) {
|
||||
access[key] = input[key];
|
||||
plugin[key] = input[key];
|
||||
}
|
||||
if (!ctx) {
|
||||
throw new Error("ctx is required");
|
||||
}
|
||||
access.ctx = ctx;
|
||||
return access;
|
||||
plugin.setCtx(ctx);
|
||||
return plugin;
|
||||
}
|
||||
|
|
|
@ -11,12 +11,15 @@
|
|||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
|
||||
import { ref } from "vue";
|
||||
import { ref, inject } from "vue";
|
||||
|
||||
defineOptions({
|
||||
name: "ApiTest"
|
||||
});
|
||||
|
||||
const getScope: any = inject("get:scope");
|
||||
const getPluginType: any = inject("get:plugin:type");
|
||||
|
||||
const props = defineProps<{} & ComponentPropsType>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
@ -31,16 +34,20 @@ const doTest = async () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const { form } = getScope();
|
||||
const pluginType = getPluginType();
|
||||
|
||||
message.value = "";
|
||||
hasError.value = false;
|
||||
loading.value = true;
|
||||
debugger;
|
||||
try {
|
||||
const res = await doRequest(
|
||||
{
|
||||
type: props.type,
|
||||
typeName: props.typeName,
|
||||
type: pluginType,
|
||||
typeName: form.type,
|
||||
action: props.action,
|
||||
input: props.form
|
||||
input: form
|
||||
},
|
||||
{
|
||||
onError(err: any) {
|
||||
|
@ -50,9 +57,7 @@ const doTest = async () => {
|
|||
showErrorNotify: false
|
||||
}
|
||||
);
|
||||
if (res && res.length > 0) {
|
||||
message.value = "测试请求成功";
|
||||
}
|
||||
message.value = "测试请求成功";
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,9 @@ const emit = defineEmits<{
|
|||
const attrs = useAttrs();
|
||||
|
||||
const getCurrentPluginDefine: any = inject("getCurrentPluginDefine");
|
||||
const getScope: any = inject("get:scope");
|
||||
const getPluginType: any = inject("get:plugin:type");
|
||||
|
||||
const optionsRef = ref([]);
|
||||
const message = ref("");
|
||||
const hasError = ref(false);
|
||||
|
@ -75,13 +78,16 @@ const getOptions = async () => {
|
|||
hasError.value = false;
|
||||
loading.value = true;
|
||||
optionsRef.value = [];
|
||||
const { form } = getScope();
|
||||
const pluginType = getPluginType();
|
||||
|
||||
try {
|
||||
const res = await doRequest(
|
||||
{
|
||||
type: props.type,
|
||||
typeName: props.typeName,
|
||||
type: pluginType,
|
||||
typeName: form.type,
|
||||
action: props.action,
|
||||
input: props.form
|
||||
input: form
|
||||
},
|
||||
{
|
||||
onError(err: any) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { request } from "/@/api/service";
|
||||
export type ComponentPropsType = {
|
||||
type: string;
|
||||
typeName: string;
|
||||
action?: string;
|
||||
form: any;
|
||||
type?: string;
|
||||
typeName?: string;
|
||||
action: string;
|
||||
form?: any;
|
||||
value?: any;
|
||||
};
|
||||
export type RequestHandleReq<T = any> = {
|
||||
|
@ -15,7 +15,7 @@ export type RequestHandleReq<T = any> = {
|
|||
};
|
||||
|
||||
export async function doRequest(req: RequestHandleReq, opts: any = {}) {
|
||||
const url = req.type === "access" ? "/pi/handle/access" : "/pi/handle/plugin";
|
||||
const url = `/pi/handle/${req.type}`;
|
||||
const { typeName, action, data, input } = req;
|
||||
const res = await request({
|
||||
url,
|
||||
|
|
|
@ -19,7 +19,6 @@ defineOptions({
|
|||
});
|
||||
|
||||
const props = defineProps<ComponentPropsType>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
"update:value": any;
|
||||
}>();
|
||||
|
|
|
@ -6,6 +6,9 @@ import SecretPlainGetter from "/@/views/certd/access/access-selector/access/secr
|
|||
|
||||
export function getCommonColumnDefine(crudExpose: any, typeRef: any, api: any) {
|
||||
provide("accessApi", api);
|
||||
provide("get:plugin:type", () => {
|
||||
return "access";
|
||||
});
|
||||
const AccessTypeDictRef = dict({
|
||||
url: "/pi/access/accessTypeDict"
|
||||
});
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import { ColumnCompositionProps, dict } from "@fast-crud/fast-crud";
|
||||
import { ColumnCompositionProps, compute, dict } from "@fast-crud/fast-crud";
|
||||
import { computed, provide, ref, toRef } from "vue";
|
||||
import { useReference } from "/@/use/use-refrence";
|
||||
import { forEach, get, merge, set } from "lodash-es";
|
||||
|
||||
export function getCommonColumnDefine(crudExpose: any, typeRef: any, api: any) {
|
||||
provide("notificationApi", api);
|
||||
provide("get:plugin:type", () => {
|
||||
return "notification";
|
||||
});
|
||||
const notificationTypeDictRef = dict({
|
||||
url: "/pi/notification/getTypeDict"
|
||||
});
|
||||
|
@ -125,6 +128,26 @@ export function getCommonColumnDefine(crudExpose: any, typeRef: any, api: any) {
|
|||
})
|
||||
}
|
||||
} as ColumnCompositionProps,
|
||||
test: {
|
||||
title: "测试",
|
||||
form: {
|
||||
component: {
|
||||
name: "api-test",
|
||||
type: "notification",
|
||||
typeName: compute(({ form }) => {
|
||||
return form.type;
|
||||
}),
|
||||
action: "TestRequest",
|
||||
form: compute(({ form }) => {
|
||||
return form;
|
||||
})
|
||||
},
|
||||
order: 999
|
||||
},
|
||||
column: {
|
||||
show: false
|
||||
}
|
||||
},
|
||||
setting: {
|
||||
column: { show: false },
|
||||
form: {
|
||||
|
|
|
@ -222,6 +222,9 @@ export default {
|
|||
provide("getCurrentPluginDefine", () => {
|
||||
return currentPluginDefine;
|
||||
});
|
||||
provide("get:plugin:type", () => {
|
||||
return "plugin";
|
||||
});
|
||||
|
||||
function getContext() {
|
||||
return {
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { Constants } from '@certd/lib-server';
|
||||
import { AccessRequestHandleReq, ITaskPlugin, newAccess, pluginRegistry, PluginRequestHandleReq, TaskInstanceContext } from '@certd/pipeline';
|
||||
import {
|
||||
AccessRequestHandleReq,
|
||||
ITaskPlugin,
|
||||
newAccess,
|
||||
newNotification,
|
||||
NotificationRequestHandleReq,
|
||||
pluginRegistry,
|
||||
PluginRequestHandleReq,
|
||||
TaskInstanceContext,
|
||||
} from '@certd/pipeline';
|
||||
import { BaseController } from '@certd/lib-server';
|
||||
import { AccessService } from '../../modules/pipeline/service/access-service.js';
|
||||
import { EmailService } from '../../modules/basic/service/email-service.js';
|
||||
import { AccessGetter } from '../../modules/pipeline/service/access-getter.js';
|
||||
import { http, HttpRequestConfig, logger, mergeUtils, utils } from '@certd/basic';
|
||||
import { NotificationService } from '../../modules/pipeline/service/notification-service.js';
|
||||
|
||||
@Provide()
|
||||
@Controller('/api/pi/handle')
|
||||
|
@ -16,12 +26,18 @@ export class HandleController extends BaseController {
|
|||
@Inject()
|
||||
emailService: EmailService;
|
||||
|
||||
@Inject()
|
||||
notificationService: NotificationService;
|
||||
|
||||
@Post('/access', { summary: Constants.per.authOnly })
|
||||
async accessRequest(@Body(ALL) body: AccessRequestHandleReq) {
|
||||
let inputAccess = body.input.access;
|
||||
if (body.input.id > 0) {
|
||||
const oldEntity = await this.accessService.info(body.input.id);
|
||||
if (oldEntity) {
|
||||
if (oldEntity.userId !== this.getUserId()) {
|
||||
throw new Error('access not found');
|
||||
}
|
||||
const param: any = {
|
||||
type: body.typeName,
|
||||
setting: JSON.stringify(body.input.access),
|
||||
|
@ -38,6 +54,34 @@ export class HandleController extends BaseController {
|
|||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/notification', { summary: Constants.per.authOnly })
|
||||
async notificationRequest(@Body(ALL) body: NotificationRequestHandleReq) {
|
||||
const input = body.input.body;
|
||||
// if (body.input.id > 0) {
|
||||
// const oldEntity = await this.notificationService.info(body.input.id);
|
||||
// if (oldEntity) {
|
||||
// if (oldEntity.userId !== this.getUserId()) {
|
||||
// throw new Error('notification not found');
|
||||
// }
|
||||
// const param: any = {
|
||||
// type: body.typeName,
|
||||
// setting: JSON.stringify(body.input.access),
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
|
||||
const notification = newNotification(body.typeName, input, {
|
||||
http,
|
||||
logger,
|
||||
utils,
|
||||
emailService: this.emailService,
|
||||
});
|
||||
|
||||
const res = await notification.onRequest(body);
|
||||
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/plugin', { summary: Constants.per.authOnly })
|
||||
async pluginRequest(@Body(ALL) body: PluginRequestHandleReq) {
|
||||
const userId = this.getUserId();
|
||||
|
|
|
@ -7,7 +7,7 @@ import { CertInfo } from '@certd/plugin-cert';
|
|||
title: '部署到腾讯云CDN',
|
||||
icon: 'svg:icon-tencentcloud',
|
||||
group: pluginGroups.tencent.key,
|
||||
desc: '可能不支持国际版',
|
||||
desc: '已废弃,请使用v2版',
|
||||
default: {
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
|
|
Loading…
Reference in New Issue