From cbccd9e3d0a4c24aba772af62734666d40b22c57 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 26 Nov 2024 11:12:22 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=80=9A=E7=9F=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89webhook=E3=80=81anpush=E3=80=81iyuu?= =?UTF-8?q?=E3=80=81server=E9=85=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide/install/baota/index.md | 2 +- .../core/pipeline/src/notification/api.ts | 4 +- .../src/views/certd/access/crud.tsx | 5 -- .../src/views/certd/notification/crud.tsx | 6 +- .../notification-selector/modal/crud.tsx | 7 ++ .../plugin-notification/anpush/index.ts | 48 +++++++++++ .../src/plugins/plugin-notification/index.ts | 4 + .../plugins/plugin-notification/iyuu/index.ts | 36 ++++++++ .../plugin-notification/serverchan/index.ts | 59 +++++++++++++ .../plugin-notification/webhook/index.ts | 83 +++++++++++++++++++ 10 files changed, 245 insertions(+), 9 deletions(-) create mode 100644 packages/ui/certd-server/src/plugins/plugin-notification/anpush/index.ts create mode 100644 packages/ui/certd-server/src/plugins/plugin-notification/iyuu/index.ts create mode 100644 packages/ui/certd-server/src/plugins/plugin-notification/serverchan/index.ts create mode 100644 packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts diff --git a/docs/guide/install/baota/index.md b/docs/guide/install/baota/index.md index 8f77a8a6..3ee002c4 100644 --- a/docs/guide/install/baota/index.md +++ b/docs/guide/install/baota/index.md @@ -40,7 +40,7 @@ admin/123456 ## 三、如何升级 ### 1. 应用商店安装,直接更新镜像即可 - +`docker`->`容器编排`->`左侧选择Certd-xxxx`->`更新镜像` ![img.png](./images/upgrade.png) diff --git a/packages/core/pipeline/src/notification/api.ts b/packages/core/pipeline/src/notification/api.ts index 338b8033..7920c505 100644 --- a/packages/core/pipeline/src/notification/api.ts +++ b/packages/core/pipeline/src/notification/api.ts @@ -97,8 +97,8 @@ export abstract class BaseNotification implements INotification { async onTestRequest() { await this.send({ userId: 0, - title: "测试通知", - content: "测试通知", + title: "【Certd】测试通知", + content: "测试通知\n\n查看详情:http://www.baidu.com", pipeline: { id: 1, title: "测试流水线", diff --git a/packages/ui/certd-client/src/views/certd/access/crud.tsx b/packages/ui/certd-client/src/views/certd/access/crud.tsx index 3b2b73ab..77c34caf 100644 --- a/packages/ui/certd-client/src/views/certd/access/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/access/crud.tsx @@ -37,11 +37,6 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat editRequest, delRequest }, - form: { - labelCol: { - span: 6 - } - }, rowHandle: { width: 200 }, diff --git a/packages/ui/certd-client/src/views/certd/notification/crud.tsx b/packages/ui/certd-client/src/views/certd/notification/crud.tsx index f3ca01a1..22c76c15 100644 --- a/packages/ui/certd-client/src/views/certd/notification/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/notification/crud.tsx @@ -39,7 +39,11 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat }, form: { labelCol: { - span: 6 + //固定label宽度 + span: null, + style: { + width: "145px" + } } }, rowHandle: { diff --git a/packages/ui/certd-client/src/views/certd/notification/notification-selector/modal/crud.tsx b/packages/ui/certd-client/src/views/certd/notification/notification-selector/modal/crud.tsx index fa874d66..64a43eb2 100644 --- a/packages/ui/certd-client/src/views/certd/notification/notification-selector/modal/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/notification/notification-selector/modal/crud.tsx @@ -58,6 +58,13 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat form: { wrapper: { width: "1050px" + }, + labelCol: { + //固定label宽度 + span: null, + style: { + width: "145px" + } } }, rowHandle: { diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/anpush/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/anpush/index.ts new file mode 100644 index 00000000..dbc8cc6e --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-notification/anpush/index.ts @@ -0,0 +1,48 @@ +import { BaseNotification, IsNotification, NotificationBody, NotificationInput } from '@certd/pipeline'; + +@IsNotification({ + name: 'anpush', + title: 'AnPush', + desc: 'https://anpush.com', +}) +export class AnPushNotification extends BaseNotification { + @NotificationInput({ + title: 'API密钥', + component: { + placeholder: '', + }, + helper: '[获取API密钥](https://anpush.com/push/tool) ', + required: true, + }) + token = ''; + + @NotificationInput({ + title: '通道ID', + component: { + placeholder: '', + }, + helper: '[获取通道ID](https://anpush.com/push/setting)创建通道,复制通道id,填入此处', + required: true, + }) + channel = ''; + + async send(body: NotificationBody) { + if (!this.token) { + throw new Error('token不能为空'); + } + const config = { + url: `https://api.anpush.com/push/${this.token}`, + method: 'POST', + timeout: 0, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + data: { + title: body.title, + content: body.content, + channel: this.channel, + }, + }; + await this.http.request(config); + } +} diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/index.ts index c4d75996..510fe10e 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/index.ts @@ -1,2 +1,6 @@ export * from './qywx/index.js'; export * from './email/index.js'; +export * from './iyuu/index.js'; +export * from './webhook/index.js'; +export * from './serverchan/index.js'; +export * from './anpush/index.js'; diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/iyuu/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/iyuu/index.ts new file mode 100644 index 00000000..f7dbe2d3 --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-notification/iyuu/index.ts @@ -0,0 +1,36 @@ +import { BaseNotification, IsNotification, NotificationBody, NotificationInput } from '@certd/pipeline'; + +@IsNotification({ + name: 'iyuu', + title: '爱语飞飞微信通知(iyuu)', + desc: 'https://iyuu.cn/', +}) +export class IyuuNotification extends BaseNotification { + @NotificationInput({ + title: 'Token令牌', + component: { + placeholder: '', + }, + helper: 'https://iyuu.cn/ 微信扫码获取', + required: true, + }) + token = ''; + + async send(body: NotificationBody) { + if (!this.token) { + throw new Error('token不能为空'); + } + const res = await this.http.request({ + url: `https://iyuu.cn/${this.token}.send`, + method: 'POST', + data: { + text: body.title, + desp: body.content, + }, + }); + + if (res.errcode !== 0) { + throw new Error(res.errmsg); + } + } +} diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/serverchan/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/serverchan/index.ts new file mode 100644 index 00000000..d23855c1 --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-notification/serverchan/index.ts @@ -0,0 +1,59 @@ +import { BaseNotification, IsNotification, NotificationBody, NotificationInput } from '@certd/pipeline'; + +@IsNotification({ + name: 'serverchan', + title: 'Server酱', + desc: 'https://sct.ftqq.com/', +}) +export class ServerChanNotification extends BaseNotification { + @NotificationInput({ + title: '服务地址', + value: 'https://sctapi.ftqq.com', + required: true, + }) + endpoint = 'https://sctapi.ftqq.com'; + + @NotificationInput({ + title: 'SendKey', + component: { + placeholder: 'https://sctapi.ftqq.com/.send', + }, + helper: 'https://sct.ftqq.com/ 微信扫码获取', + required: true, + }) + sendKey = ''; + + @NotificationInput({ + title: '消息通道号', + component: { + placeholder: '9|66', + }, + helper: '可以不填,最多两个通道,[通道配置说明](https://sct.ftqq.com/sendkey)', + required: false, + }) + channel: string; + + @NotificationInput({ + title: '是否隐藏IP', + component: { + name: 'a-switch', + vModel: 'checked', + }, + required: false, + }) + noip: boolean; + + async send(body: NotificationBody) { + if (!this.sendKey) { + throw new Error('sendKey不能为空'); + } + await this.http.request({ + url: `${this.endpoint}/${this.sendKey}.send`, + method: 'POST', + data: { + text: body.title, + desp: body.content, + }, + }); + } +} diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts new file mode 100644 index 00000000..e425cbef --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts @@ -0,0 +1,83 @@ +import { BaseNotification, IsNotification, NotificationBody, NotificationInput } from '@certd/pipeline'; + +@IsNotification({ + name: 'webhook', + title: '自定义webhook', + desc: '根据模版自定义http请求', +}) +export class WebhookNotification extends BaseNotification { + @NotificationInput({ + title: 'webhook地址', + component: { + placeholder: '', + }, + required: true, + }) + webhook = ''; + + @NotificationInput({ + title: '请求方式', + value: 'post', + component: { + name: 'a-select', + placeholder: 'post/put', + options: [ + { value: 'post', label: 'post' }, + { value: 'put', label: 'put' }, + ], + }, + required: true, + }) + method = ''; + + @NotificationInput({ + title: 'ContentType', + value: 'json', + component: { + name: 'a-select', + options: [ + { value: 'application/json', label: 'json' }, + { value: 'application/x-www-form-urlencoded', label: 'x-www-form-urlencoded' }, + ], + }, + required: true, + }) + contentType = ''; + + @NotificationInput({ + title: '消息body模版', + value: `{ + title:"{title}", + content:"{content}" +}`, + component: { + name: 'a-textarea', + rows: 4, + }, + col: { + span: 24, + }, + helper: `根据实际的webhook接口,构建一个json对象作为参数,支持{title}和{content}两个变量,变量用{}包裹,字符串需要双引号`, + required: true, + }) + template = ''; + + async send(body: NotificationBody) { + if (!this.template) { + throw new Error('模版不能为空'); + } + + const bodyStr = this.template.replaceAll('{title}', body.title).replaceAll('{content}', body.content); + + const data = JSON.parse(bodyStr); + + await this.http.request({ + url: this.webhook, + method: this.method, + headers: { + 'Content-Type': `${this.contentType}; charset=UTF-8`, + }, + data: data, + }); + } +}