mirror of
https://github.com/certd/certd.git
synced 2026-05-15 20:47:31 +08:00
perf: 优化证书申请成功通知发送方式
This commit is contained in:
@@ -6,13 +6,13 @@ import * as _ from "lodash-es";
|
||||
import { IEmailService } from "../service/index.js";
|
||||
|
||||
export type NotificationBody = {
|
||||
userId: number;
|
||||
userId?: number;
|
||||
title: string;
|
||||
content: string;
|
||||
pipeline: Pipeline;
|
||||
pipelineId: number;
|
||||
pipeline?: Pipeline;
|
||||
pipelineId?: number;
|
||||
result?: HistoryResult;
|
||||
historyId: number;
|
||||
historyId?: number;
|
||||
errorMessage?: string;
|
||||
url?: string;
|
||||
};
|
||||
@@ -39,6 +39,7 @@ export type NotificationDefine = Registrable & {
|
||||
export type NotificationInstanceConfig = {
|
||||
id: number;
|
||||
type: string;
|
||||
name: string;
|
||||
userId: number;
|
||||
setting: {
|
||||
[key: string]: any;
|
||||
@@ -47,6 +48,7 @@ export type NotificationInstanceConfig = {
|
||||
|
||||
export interface INotificationService {
|
||||
getById(id: number): Promise<NotificationInstanceConfig>;
|
||||
getDefault(): Promise<NotificationInstanceConfig>;
|
||||
}
|
||||
|
||||
export interface INotification {
|
||||
@@ -97,7 +99,7 @@ export abstract class BaseNotification implements INotification {
|
||||
async onTestRequest() {
|
||||
await this.send({
|
||||
userId: 0,
|
||||
title: "【Certd】测试通知",
|
||||
title: "【Certd】测试通知,标题长度测试、测试、测试",
|
||||
content: "测试通知",
|
||||
pipeline: {
|
||||
id: 1,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { Decorator } from "../decorator/index.js";
|
||||
import * as _ from "lodash-es";
|
||||
import { notificationRegistry } from "./registry.js";
|
||||
import { NotificationContext, NotificationDefine, NotificationInputDefine } from "./api.js";
|
||||
import { NotificationBody, NotificationContext, NotificationDefine, NotificationInputDefine, NotificationInstanceConfig } from "./api.js";
|
||||
|
||||
// 提供一个唯一 key
|
||||
export const NOTIFICATION_CLASS_KEY = "pipeline:notification";
|
||||
@@ -38,7 +38,7 @@ export function NotificationInput(input?: NotificationInputDefine): PropertyDeco
|
||||
};
|
||||
}
|
||||
|
||||
export function newNotification(type: string, input: any, ctx: NotificationContext) {
|
||||
export async function newNotification(type: string, input: any, ctx: NotificationContext) {
|
||||
const register = notificationRegistry.get(type);
|
||||
if (register == null) {
|
||||
throw new Error(`notification ${type} not found`);
|
||||
@@ -52,5 +52,11 @@ export function newNotification(type: string, input: any, ctx: NotificationConte
|
||||
throw new Error("ctx is required");
|
||||
}
|
||||
plugin.setCtx(ctx);
|
||||
await plugin.onInstance();
|
||||
return plugin;
|
||||
}
|
||||
|
||||
export async function sendNotification(opts: { config: NotificationInstanceConfig; ctx: NotificationContext; body: NotificationBody }) {
|
||||
const notification = await newNotification(opts.config.type, opts.config.setting, opts.ctx);
|
||||
await notification.send(opts.body);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user