From b54ae272ebc2d31b32b049d44e2299a6be7f153c Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 25 Nov 2024 11:35:16 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=80=9A=E7=9F=A5=E6=B8=A0=E9=81=93?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=B5=8B=E8=AF=95=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/pipeline/src/access/api.ts | 4 ++ .../core/pipeline/src/access/decorator.ts | 2 +- .../core/pipeline/src/notification/api.ts | 15 ++++++ .../pipeline/src/notification/decorator.ts | 8 ++-- .../components/plugins/common/api-test.vue | 19 +++++--- .../plugins/common/remote-select.vue | 12 +++-- .../src/components/plugins/lib/index.ts | 10 ++-- .../plugins/synology/device-id-getter.vue | 1 - .../src/views/certd/access/common.tsx | 3 ++ .../src/views/certd/notification/common.tsx | 25 +++++++++- .../pipeline/component/step-form/index.vue | 3 ++ .../controller/pipeline/handle-controller.ts | 46 ++++++++++++++++++- .../plugin/deploy-to-cdn/index.ts | 2 +- 13 files changed, 126 insertions(+), 24 deletions(-) diff --git a/packages/core/pipeline/src/access/api.ts b/packages/core/pipeline/src/access/api.ts index 72937697..a350e8ef 100644 --- a/packages/core/pipeline/src/access/api.ts +++ b/packages/core/pipeline/src/access/api.ts @@ -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"); diff --git a/packages/core/pipeline/src/access/decorator.ts b/packages/core/pipeline/src/access/decorator.ts index 2abcd904..a0c19eee 100644 --- a/packages/core/pipeline/src/access/decorator.ts +++ b/packages/core/pipeline/src/access/decorator.ts @@ -56,6 +56,6 @@ export function newAccess(type: string, input: any, ctx?: AccessContext) { utils, }; } - access.ctx = ctx; + access.setCtx(ctx); return access; } diff --git a/packages/core/pipeline/src/notification/api.ts b/packages/core/pipeline/src/notification/api.ts index 8488a690..338b8033 100644 --- a/packages/core/pipeline/src/notification/api.ts +++ b/packages/core/pipeline/src/notification/api.ts @@ -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", + }); + } } diff --git a/packages/core/pipeline/src/notification/decorator.ts b/packages/core/pipeline/src/notification/decorator.ts index ac80b14c..66b17b4d 100644 --- a/packages/core/pipeline/src/notification/decorator.ts +++ b/packages/core/pipeline/src/notification/decorator.ts @@ -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; } diff --git a/packages/ui/certd-client/src/components/plugins/common/api-test.vue b/packages/ui/certd-client/src/components/plugins/common/api-test.vue index 7749e49f..23e3f60e 100644 --- a/packages/ui/certd-client/src/components/plugins/common/api-test.vue +++ b/packages/ui/certd-client/src/components/plugins/common/api-test.vue @@ -11,12 +11,15 @@