mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
perf: 通知渠道支持测试按钮
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user