mirror of https://github.com/certd/certd
feat: save files
parent
671d273e2f
commit
99522fb49a
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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<void> {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue