From 3254afc75640eed3729d0fc02a818fefbe5c7fc3 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 26 Nov 2024 23:11:20 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=87=AA=E5=AE=9A=E4=B9=89webhook?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=AF=A6=E7=BB=86=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/certd/notification/common.tsx | 5 ++- .../plugin-notification/webhook/index.ts | 42 ++++++++++++------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/packages/ui/certd-client/src/views/certd/notification/common.tsx b/packages/ui/certd-client/src/views/certd/notification/common.tsx index 95d47196..de81152a 100644 --- a/packages/ui/certd-client/src/views/certd/notification/common.tsx +++ b/packages/ui/certd-client/src/views/certd/notification/common.tsx @@ -151,7 +151,10 @@ export function getCommonColumnDefine(crudExpose: any, typeRef: any, api: any) { name: "api-test", action: "TestRequest" }, - order: 999 + order: 999, + col: { + span: 24 + } }, column: { show: false 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 index b813fb8e..b32cf808 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts @@ -48,10 +48,11 @@ export class WebhookNotification extends BaseNotification { title: 'Headers', component: { name: 'a-textarea', + vModel: 'value', rows: 3, }, helper: '一行一个,格式为key:value', - required: true, + required: false, }) headers = ''; @@ -83,18 +84,31 @@ export class WebhookNotification extends BaseNotification { const data = JSON.parse(bodyStr); const headers: any = {}; - this.headers.split('\n').forEach(item => { - const [key, value] = item.trim().split(':'); - headers[key] = value; - }); - await this.http.request({ - url: this.webhook, - method: this.method, - headers: { - 'Content-Type': `${this.contentType}; charset=UTF-8`, - ...headers, - }, - data: data, - }); + if (this.headers && this.headers.trim()) { + this.headers.split('\n').forEach(item => { + item = item.trim(); + if (item) { + const [key, value] = item.split(':'); + headers[key] = value; + } + }); + } + + try { + await this.http.request({ + url: this.webhook, + method: this.method, + headers: { + 'Content-Type': `${this.contentType}; charset=UTF-8`, + ...headers, + }, + data: data, + }); + } catch (e) { + if (e.response?.data) { + throw new Error(e.message + ',' + JSON.stringify(e.response.data)); + } + throw e; + } } }