perf: 通知渠道支持测试按钮

This commit is contained in:
xiaojunnuo
2024-11-25 11:35:16 +08:00
parent 3af6d96e6e
commit b54ae272eb
13 changed files with 126 additions and 24 deletions
+4
View File
@@ -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;
}