perf: 首页新增修改密码提示

This commit is contained in:
xiaojunnuo
2024-11-30 22:35:26 +08:00
parent 61d6b06c56
commit 0772d3b3fd
10 changed files with 162 additions and 92 deletions
+13 -1
View File
@@ -4,6 +4,7 @@ import { FormItemProps, HistoryResult, Pipeline } from "../dt/index.js";
import { HttpClient, ILogger, utils } from "@certd/basic";
import * as _ from "lodash-es";
import { IEmailService } from "../service/index.js";
import { isPlus } from "@certd/plus-core";
export type NotificationBody = {
userId?: number;
@@ -65,9 +66,17 @@ export type NotificationContext = {
};
export abstract class BaseNotification implements INotification {
define!: NotificationDefine;
ctx!: NotificationContext;
http!: HttpClient;
logger!: ILogger;
async doSend(body: NotificationBody) {
if (this.define.needPlus && !isPlus()) {
body.content = `${body.content}\n\n注意:此通知渠道已调整为专业版功能,后续版本将不再支持发送,请尽快修改或升级为专业版`;
}
return await this.send(body);
}
abstract send(body: NotificationBody): Promise<void>;
// eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -77,6 +86,9 @@ export abstract class BaseNotification implements INotification {
this.http = ctx.http;
this.logger = ctx.logger;
}
setDefine = (define: NotificationDefine) => {
this.define = define;
};
async onRequest(req: NotificationRequestHandleReq) {
if (!req.action) {
@@ -98,7 +110,7 @@ export abstract class BaseNotification implements INotification {
}
async onTestRequest() {
await this.send({
await this.doSend({
userId: 0,
title: "【Certd】测试通知,标题长度测试、测试、测试",
content: "测试通知",
@@ -2,7 +2,8 @@
import { Decorator } from "../decorator/index.js";
import * as _ from "lodash-es";
import { notificationRegistry } from "./registry.js";
import { NotificationBody, NotificationContext, NotificationDefine, NotificationInputDefine, NotificationInstanceConfig } from "./api.js";
import { BaseNotification, NotificationBody, NotificationContext, NotificationDefine, NotificationInputDefine, NotificationInstanceConfig } from "./api.js";
import { isPlus } from "@certd/plus-core";
// 提供一个唯一 key
export const NOTIFICATION_CLASS_KEY = "pipeline:notification";
@@ -43,6 +44,7 @@ export async function newNotification(type: string, input: any, ctx: Notificatio
if (register == null) {
throw new Error(`notification ${type} not found`);
}
// @ts-ignore
const plugin = new register.target();
for (const key in input) {
@@ -51,12 +53,16 @@ export async function newNotification(type: string, input: any, ctx: Notificatio
if (!ctx) {
throw new Error("ctx is required");
}
plugin.setDefine(register.define);
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);
const notification: BaseNotification = await newNotification(opts.config.type, opts.config.setting, opts.ctx);
if (notification.define.needPlus && !isPlus()) {
opts.body.content = `${opts.body.content}\n\n注意:此通知渠道已调整为专业版功能,后续版本将不再支持发送,请尽快修改或升级为专业版`;
}
await notification.doSend(opts.body);
}