mirror of https://github.com/certd/certd
perf: 优化文件下载包名
parent
39ad7597fa
commit
d9eb927b0a
|
@ -23,7 +23,7 @@
|
||||||
"qs": "^6.11.2"
|
"qs": "^6.11.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@certd/acme-client": "^1.20.9",
|
"@certd/acme-client": "workspace:^1.20.9",
|
||||||
"@rollup/plugin-commonjs": "^23.0.4",
|
"@rollup/plugin-commonjs": "^23.0.4",
|
||||||
"@rollup/plugin-json": "^6.0.0",
|
"@rollup/plugin-json": "^6.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Registry } from "../registry";
|
import { Registry } from "../registry";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export const accessRegistry = new Registry();
|
export const accessRegistry = new Registry("access");
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { fileUtils } from "../utils/util.file";
|
import { fileUtils } from "../utils";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import { logger } from "../utils";
|
||||||
|
|
||||||
export type FileStoreOptions = {
|
export type FileStoreOptions = {
|
||||||
rootDir?: string;
|
rootDir?: string;
|
||||||
|
@ -30,6 +31,7 @@ export class FileStore {
|
||||||
const localPath = this.buildFilePath(filename);
|
const localPath = this.buildFilePath(filename);
|
||||||
|
|
||||||
fs.writeFileSync(localPath, file);
|
fs.writeFileSync(localPath, file);
|
||||||
|
logger.info(`写入文件:${localPath}`);
|
||||||
return localPath;
|
return localPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { IAccessService } from "../access";
|
||||||
import { IEmailService } from "../service";
|
import { IEmailService } from "../service";
|
||||||
import { IContext } from "../core";
|
import { IContext } from "../core";
|
||||||
import { AxiosInstance } from "axios";
|
import { AxiosInstance } from "axios";
|
||||||
|
import { logger } from "../utils";
|
||||||
|
|
||||||
export enum ContextScope {
|
export enum ContextScope {
|
||||||
global,
|
global,
|
||||||
|
@ -89,6 +90,7 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin {
|
||||||
}
|
}
|
||||||
saveFile(filename: string, file: Buffer) {
|
saveFile(filename: string, file: Buffer) {
|
||||||
const filePath = this.ctx.fileStore.writeFile(filename, file);
|
const filePath = this.ctx.fileStore.writeFile(filename, file);
|
||||||
|
logger.info(`saveFile:${filePath}`);
|
||||||
this._result.files!.push({
|
this._result.files!.push({
|
||||||
id: this.randomFileId(),
|
id: this.randomFileId(),
|
||||||
filename,
|
filename,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Registry } from "../registry";
|
import { Registry } from "../registry";
|
||||||
import { AbstractTaskPlugin } from "./api";
|
import { AbstractTaskPlugin } from "./api";
|
||||||
|
|
||||||
export const pluginRegistry = new Registry<AbstractTaskPlugin>();
|
export const pluginRegistry = new Registry<AbstractTaskPlugin>("plugin");
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { logger } from "../utils";
|
||||||
|
|
||||||
export type Registrable = {
|
export type Registrable = {
|
||||||
name: string;
|
name: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -9,15 +11,21 @@ export type RegistryItem<T> = {
|
||||||
target: T;
|
target: T;
|
||||||
};
|
};
|
||||||
export class Registry<T> {
|
export class Registry<T> {
|
||||||
|
type = "";
|
||||||
storage: {
|
storage: {
|
||||||
[key: string]: RegistryItem<T>;
|
[key: string]: RegistryItem<T>;
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
|
constructor(type: string) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
register(key: string, value: RegistryItem<T>) {
|
register(key: string, value: RegistryItem<T>) {
|
||||||
if (!key || value == null) {
|
if (!key || value == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.storage[key] = value;
|
this.storage[key] = value;
|
||||||
|
logger.info(`注册插件:${this.type}:${key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
get(name: string): RegistryItem<T> {
|
get(name: string): RegistryItem<T> {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import sleep from "./util.sleep";
|
import sleep from "./util.sleep";
|
||||||
import { request } from "./util.request";
|
import { request } from "./util.request";
|
||||||
export * from "./util.log";
|
export * from "./util.log";
|
||||||
|
export * from "./util.file";
|
||||||
export const utils = {
|
export const utils = {
|
||||||
sleep,
|
sleep,
|
||||||
http: request,
|
http: request,
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certd/acme-client": "^1.20.9",
|
"@certd/acme-client": "workspace:^1.20.9",
|
||||||
"@certd/pipeline": "^1.20.9",
|
"@certd/pipeline": "workspace:^1.20.9",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"node-forge": "^0.10.0"
|
"node-forge": "^0.10.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
import { Registry } from "@certd/pipeline";
|
import { Registry } from "@certd/pipeline";
|
||||||
|
|
||||||
export const dnsProviderRegistry = new Registry();
|
export const dnsProviderRegistry = new Registry("dnsProvider");
|
||||||
|
|
|
@ -3,7 +3,7 @@ import * as acme from "@certd/acme-client";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { Challenge } from "@certd/acme-client/types/rfc8555";
|
import { Challenge } from "@certd/acme-client/types/rfc8555";
|
||||||
import { Logger } from "log4js";
|
import { Logger } from "log4js";
|
||||||
import { IContext } from "@certd/pipeline/src/core/context";
|
import { IContext } from "@certd/pipeline";
|
||||||
import { IDnsProvider } from "../../dns-provider";
|
import { IDnsProvider } from "../../dns-provider";
|
||||||
export type CertInfo = {
|
export type CertInfo = {
|
||||||
crt: string;
|
crt: string;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { Logger } from "log4js";
|
||||||
import { DnsProviderDefine, dnsProviderRegistry } from "../../dns-provider";
|
import { DnsProviderDefine, dnsProviderRegistry } from "../../dns-provider";
|
||||||
import { CertReader } from "./cert-reader";
|
import { CertReader } from "./cert-reader";
|
||||||
import JSZip from "jszip";
|
import JSZip from "jszip";
|
||||||
|
import { fileUtils } from "@certd/pipeline";
|
||||||
export { CertReader };
|
export { CertReader };
|
||||||
export type { CertInfo };
|
export type { CertInfo };
|
||||||
|
|
||||||
|
@ -133,11 +134,11 @@ export class CertApplyPlugin extends AbstractTaskPlugin {
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const oldCert = await this.condition();
|
const oldCert = await this.condition();
|
||||||
if (oldCert != null) {
|
if (oldCert != null) {
|
||||||
return await this.output(oldCert.toCertInfo());
|
return await this.output(oldCert);
|
||||||
}
|
}
|
||||||
const cert = await this.doCertApply();
|
const cert = await this.doCertApply();
|
||||||
if (cert != null) {
|
if (cert != null) {
|
||||||
await this.output(cert.toCertInfo());
|
await this.output(cert);
|
||||||
//清空后续任务的状态,让后续任务能够重新执行
|
//清空后续任务的状态,让后续任务能够重新执行
|
||||||
this.clearLastStatus();
|
this.clearLastStatus();
|
||||||
} else {
|
} else {
|
||||||
|
@ -145,17 +146,24 @@ export class CertApplyPlugin extends AbstractTaskPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async output(cert: CertInfo) {
|
async output(certReader: CertReader) {
|
||||||
|
const cert: CertInfo = certReader.toCertInfo();
|
||||||
this.cert = cert;
|
this.cert = cert;
|
||||||
await this.zipCert(cert);
|
// this.logger.info(JSON.stringify(certReader.detail));
|
||||||
|
const applyTime = dayjs(certReader.detail.validity.notBefore).format("YYYYMMDDHHmmss");
|
||||||
|
await this.zipCert(cert, applyTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
async zipCert(cert: CertInfo) {
|
async zipCert(cert: CertInfo, applyTime: string) {
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
zip.file("cert.crt", cert.crt);
|
zip.file("cert.crt", cert.crt);
|
||||||
zip.file("cert.key", cert.key);
|
zip.file("cert.key", cert.key);
|
||||||
|
const domain_name = this.domains[0].replace(".", "_").replace("*", "_");
|
||||||
|
const filename = `cert_${domain_name}_${applyTime}.zip`;
|
||||||
const content = await zip.generateAsync({ type: "nodebuffer" });
|
const content = await zip.generateAsync({ type: "nodebuffer" });
|
||||||
this.saveFile("cert.zip", content);
|
this.saveFile(filename, content);
|
||||||
|
this.logger.info(`getFileRootDir:${fileUtils.getFileRootDir("11")}`);
|
||||||
|
this.logger.info(`保存文件:${filename}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
"shelljs": "^0.8.5"
|
"shelljs": "^0.8.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@certd/pipeline": "^1.20.9",
|
"@certd/pipeline": "workspace:^1.20.9",
|
||||||
"@rollup/plugin-commonjs": "^23.0.4",
|
"@rollup/plugin-commonjs": "^23.0.4",
|
||||||
"@rollup/plugin-json": "^6.0.0",
|
"@rollup/plugin-json": "^6.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||||
|
|
|
@ -26,10 +26,10 @@
|
||||||
"@ant-design/icons-vue": "^6.1.0",
|
"@ant-design/icons-vue": "^6.1.0",
|
||||||
"@aws-sdk/client-s3": "^3.383.0",
|
"@aws-sdk/client-s3": "^3.383.0",
|
||||||
"@aws-sdk/s3-request-presigner": "^3.383.0",
|
"@aws-sdk/s3-request-presigner": "^3.383.0",
|
||||||
"@fast-crud/fast-crud": "^1.20.1",
|
"@fast-crud/fast-crud": "^1.20.2",
|
||||||
"@fast-crud/fast-extends": "^1.20.1",
|
"@fast-crud/fast-extends": "^1.20.2",
|
||||||
"@fast-crud/ui-antdv4": "^1.20.1",
|
"@fast-crud/ui-antdv4": "^1.20.2",
|
||||||
"@fast-crud/ui-interface": "^1.20.1",
|
"@fast-crud/ui-interface": "^1.20.2",
|
||||||
"@iconify/vue": "^4.1.1",
|
"@iconify/vue": "^4.1.1",
|
||||||
"@soerenmartius/vue3-clipboard": "^0.1.2",
|
"@soerenmartius/vue3-clipboard": "^0.1.2",
|
||||||
"ant-design-vue": "^4.1.2",
|
"ant-design-vue": "^4.1.2",
|
||||||
|
|
|
@ -58,6 +58,7 @@ function install(app: App, options: any = {}) {
|
||||||
buttons: {
|
buttons: {
|
||||||
view: { type: "link", text: null, icon: "ion:eye-outline" },
|
view: { type: "link", text: null, icon: "ion:eye-outline" },
|
||||||
edit: { type: "link", text: null, icon: "ion:create-outline" },
|
edit: { type: "link", text: null, icon: "ion:create-outline" },
|
||||||
|
copy: {show:true,type: "link", text: null, icon: "ion:copy-outline"},
|
||||||
remove: { type: "link", style: { color: "red" }, text: null, icon: "ion:trash-outline" }
|
remove: { type: "link", style: { color: "red" }, text: null, icon: "ion:trash-outline" }
|
||||||
},
|
},
|
||||||
dropdown: {
|
dropdown: {
|
||||||
|
|
|
@ -21,16 +21,10 @@
|
||||||
"mig": "typeorm migration:create -n name"
|
"mig": "typeorm migration:create -n name"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certd/acme-client": "^1.20.9",
|
"@certd/acme-client": "workspace:^1.20.9",
|
||||||
"@certd/pipeline": "^1.20.9",
|
"@certd/pipeline": "workspace:^1.20.9",
|
||||||
"@certd/plugin-aliyun": "^1.20.9",
|
"@certd/plugin-cert": "workspace:^1.20.9",
|
||||||
"@certd/plugin-all": "^1.20.9",
|
"@certd/plugin-util": "workspace:^1.20.9",
|
||||||
"@certd/plugin-center": "^1.20.9",
|
|
||||||
"@certd/plugin-cert": "^1.20.9",
|
|
||||||
"@certd/plugin-host": "^1.20.9",
|
|
||||||
"@certd/plugin-huawei": "^1.20.9",
|
|
||||||
"@certd/plugin-tencent": "^1.20.9",
|
|
||||||
"@certd/plugin-util": "^1.20.9",
|
|
||||||
"@alicloud/cs20151215": "^3.0.3",
|
"@alicloud/cs20151215": "^3.0.3",
|
||||||
"@alicloud/openapi-client": "^0.4.0",
|
"@alicloud/openapi-client": "^0.4.0",
|
||||||
"@alicloud/pop-core": "^1.7.10",
|
"@alicloud/pop-core": "^1.7.10",
|
||||||
|
|
|
@ -32,6 +32,7 @@ export abstract class CrudController<T> extends BaseController {
|
||||||
@Body(ALL)
|
@Body(ALL)
|
||||||
bean
|
bean
|
||||||
) {
|
) {
|
||||||
|
delete bean.id;
|
||||||
const id = await this.getService().add(bean);
|
const id = await this.getService().add(bean);
|
||||||
return this.ok(id);
|
return this.ok(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { PipelineService } from '../service/pipeline-service';
|
||||||
import { CommonException } from '../../../basic/exception/common-exception';
|
import { CommonException } from '../../../basic/exception/common-exception';
|
||||||
import { PermissionException } from '../../../basic/exception/permission-exception';
|
import { PermissionException } from '../../../basic/exception/permission-exception';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import { logger } from '../../../utils/logger';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 证书
|
* 证书
|
||||||
|
@ -151,7 +152,7 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||||
// const filename = file.filename;
|
// const filename = file.filename;
|
||||||
// 要下载的文件的完整路径
|
// 要下载的文件的完整路径
|
||||||
const path = file.path;
|
const path = file.path;
|
||||||
|
logger.info(`download:${path}`);
|
||||||
// 以流的形式下载文件
|
// 以流的形式下载文件
|
||||||
this.ctx.attachment(path);
|
this.ctx.attachment(path);
|
||||||
this.ctx.set('Content-Type', 'application/octet-stream');
|
this.ctx.set('Content-Type', 'application/octet-stream');
|
||||||
|
|
Loading…
Reference in New Issue