diff --git a/packages/core/pipeline/src/core/file-store.ts b/packages/core/pipeline/src/core/file-store.ts index 89183ec8..fd5a3662 100644 --- a/packages/core/pipeline/src/core/file-store.ts +++ b/packages/core/pipeline/src/core/file-store.ts @@ -28,11 +28,16 @@ export class FileStore { writeFile(filename: string, file: Buffer) { const localPath = this.buildFilePath(filename); + fs.writeFileSync(localPath, file); return localPath; } private buildFilePath(filename: string) { - return path.join(this.rootDir, this.scope, dayjs().format("YYYY-MM-DD"), this.parent, filename); + const parentDir = path.join(this.rootDir, this.scope + "", dayjs().format("YYYY-MM-DD"), this.parent + ""); + if (!fs.existsSync(parentDir)) { + fs.mkdirSync(parentDir, { recursive: true }); + } + return path.join(parentDir, filename); } } diff --git a/packages/plugins/plugin-cert/package.json b/packages/plugins/plugin-cert/package.json index 53344e86..768c71a9 100644 --- a/packages/plugins/plugin-cert/package.json +++ b/packages/plugins/plugin-cert/package.json @@ -19,6 +19,7 @@ "dependencies": { "@certd/acme-client": "^1.0.6", "@certd/pipeline": "^1.0.6", + "jszip": "^3.10.1", "node-forge": "^0.10.0" }, "devDependencies": { diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts index f06f48f7..0596aba3 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts @@ -5,7 +5,7 @@ import _ from "lodash"; import { Logger } from "log4js"; import { DnsProviderDefine, dnsProviderRegistry } from "../../dns-provider"; import { CertReader } from "./cert-reader"; - +import JSZip from "jszip"; export { CertReader }; export type { CertInfo }; @@ -133,11 +133,11 @@ export class CertApplyPlugin extends AbstractTaskPlugin { async execute(): Promise { const oldCert = await this.condition(); if (oldCert != null) { - return this.output(oldCert.toCertInfo()); + return await this.output(oldCert.toCertInfo()); } const cert = await this.doCertApply(); if (cert != null) { - this.output(cert.toCertInfo()); + await this.output(cert.toCertInfo()); //清空后续任务的状态,让后续任务能够重新执行 this.clearLastStatus(); } else { @@ -145,8 +145,17 @@ export class CertApplyPlugin extends AbstractTaskPlugin { } } - output(cert: CertInfo) { + async output(cert: CertInfo) { this.cert = cert; + await this.zipCert(cert); + } + + async zipCert(cert: CertInfo) { + const zip = new JSZip(); + zip.file("cert.crt", cert.crt); + zip.file("cert.key", cert.key); + const content = await zip.generateAsync({ type: "nodebuffer" }); + this.saveFile("cert.zip", content); } /**