From 656cb89fe8f33130bbf96094668a95f527046b36 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Fri, 21 Mar 2025 12:23:59 +0800 Subject: [PATCH] chore: --- .../src/plugin/cert-plugin/custom/d.ts | 6 +++ .../src/plugin/cert-plugin/custom/index.ts | 37 +++++++++++++------ .../certd-client/src/components/pem-input.vue | 7 ++-- .../component/shortcut/task-shortcut.vue | 4 ++ .../user/pipeline/handle-controller.ts | 26 ++++++++++--- .../service/cert-apply-upload-service.ts | 28 ++++++++++++++ .../pipeline/service/pipeline-service.ts | 5 ++- 7 files changed, 92 insertions(+), 21 deletions(-) create mode 100644 packages/plugins/plugin-cert/src/plugin/cert-plugin/custom/d.ts create mode 100644 packages/ui/certd-server/src/modules/pipeline/service/cert-apply-upload-service.ts diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/custom/d.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/custom/d.ts new file mode 100644 index 00000000..1495fa0f --- /dev/null +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/custom/d.ts @@ -0,0 +1,6 @@ +import { CertInfo } from "../acme"; + +export interface ICertApplyUploadService { + getCertInfo: (opts: { certId: number; userId: number }) => Promise; + updateCert: (opts: { certId: number; cert: CertInfo; userId: number }) => Promise; +} diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/custom/index.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/custom/index.ts index 5d9f9372..d5f49ba9 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/custom/index.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/custom/index.ts @@ -2,11 +2,12 @@ import { IsTaskPlugin, pluginGroups, RunStrategy, Step, TaskInput, TaskOutput } import type { CertInfo } from "../acme.js"; import { CertReader } from "../cert-reader.js"; import { CertApplyBaseConvertPlugin } from "../base-convert.js"; -import dayjs from "dayjs"; +export * from "./d.js"; +import dayjs from "dayjs"; +import { ICertApplyUploadService } from "./d"; export { CertReader }; export type { CertInfo }; - @IsTaskPlugin({ name: "CertApplyUpload", icon: "ph:certificate", @@ -20,20 +21,21 @@ export type { CertInfo }; }, shortcut: { certUpdate: { - title: "上传证书", + title: "更新证书", icon: "ph:upload", action: "onCertUpdate", form: { columns: { crt: { title: "证书", - type: "textarea", + type: "text", form: { component: { name: "pem-input", vModel: "modelValue", textarea: { - row: 4, + rows: 4, + placeholder: "-----BEGIN CERTIFICATE-----\n...\n...\n-----END CERTIFICATE-----", }, }, rules: [{ required: true, message: "此项必填" }], @@ -42,13 +44,14 @@ export type { CertInfo }; }, key: { title: "私钥", - type: "textarea", + type: "text", form: { component: { name: "pem-input", vModel: "modelValue", textarea: { - row: 4, + rows: 4, + placeholder: "-----BEGIN PRIVATE KEY-----\n...\n...\n-----END PRIVATE KEY----- ", }, }, rules: [{ required: true, message: "此项必填" }], @@ -67,6 +70,7 @@ export class CertApplyUploadPlugin extends CertApplyBaseConvertPlugin { name: "cert-info-selector", vModel: "modelValue", }, + helper: "请不要随意修改", order: -9999, required: true, mergeScript: ` @@ -98,10 +102,10 @@ export class CertApplyUploadPlugin extends CertApplyBaseConvertPlugin { async onInit(): Promise {} async getCertFromStore() { - const siteInfoService = await this.ctx.serviceGetter.get("CertInfoService"); + const certApplyUploadService: ICertApplyUploadService = await this.ctx.serviceGetter.get("CertApplyUploadService"); - const certInfo = await siteInfoService.getCertInfo({ - certId: this.certInfoId, + const certInfo = await certApplyUploadService.getCertInfo({ + certId: Number(this.certInfoId), userId: this.pipeline.userId, }); @@ -137,7 +141,18 @@ export class CertApplyUploadPlugin extends CertApplyBaseConvertPlugin { return; } - async onCertUpdate(data: any) {} + async onCertUpdate(data: any) { + const certApplyUploadService = await this.ctx.serviceGetter.get("CertApplyUploadService"); + + await certApplyUploadService.updateCert({ + certId: this.certInfoId, + userId: this.ctx.user.id, + cert: { + crt: data.crt, + key: data.key, + }, + }); + } } new CertApplyUploadPlugin(); diff --git a/packages/ui/certd-client/src/components/pem-input.vue b/packages/ui/certd-client/src/components/pem-input.vue index 544d0f9d..fed8c308 100644 --- a/packages/ui/certd-client/src/components/pem-input.vue +++ b/packages/ui/certd-client/src/components/pem-input.vue @@ -1,6 +1,6 @@ @@ -8,6 +8,7 @@