mirror of
https://github.com/certd/certd.git
synced 2026-07-29 08:37:36 +08:00
perf: 【破坏性更新】 证书压缩包不再生成文件存储,而是实时打包下载,证书申请插件不再输出certZip
自定义插件需要压缩包时可以调用new CertReader(certInfo).buildZip() 方式获取
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Body, Controller, Get, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
|
||||
import { BaseController, Constants, PermissionException } from "@certd/lib-server";
|
||||
import { StorageService } from "../../../modules/pipeline/service/storage-service.js";
|
||||
@@ -6,6 +6,7 @@ import { CertReader } from "@certd/plugin-cert";
|
||||
import { UserSettingsService } from "../../../modules/mine/service/user-settings-service.js";
|
||||
import { UserGrantSetting } from "../../../modules/mine/service/models.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { logger } from "@certd/basic";
|
||||
|
||||
@Provide()
|
||||
@Controller("/api/pi/cert")
|
||||
@@ -57,4 +58,38 @@ export class CertController extends BaseController {
|
||||
const certDetail = CertReader.readCertDetail(crt);
|
||||
return this.ok(certDetail);
|
||||
}
|
||||
|
||||
@Get("/downloadZip", { description: Constants.per.authOnly, summary: "下载流水线证书压缩包" })
|
||||
async downloadZip(@Query("id") id: number) {
|
||||
const { userId } = await this.getProjectUserIdRead();
|
||||
|
||||
const pipelineUserId = await this.pipelineService.getPipelineUserId(id);
|
||||
|
||||
if (pipelineUserId !== userId) {
|
||||
const isAdmin = await this.isAdmin();
|
||||
if (!isAdmin) {
|
||||
throw new PermissionException();
|
||||
}
|
||||
const setting = await this.userSettingsService.getSetting<UserGrantSetting>(pipelineUserId, null, UserGrantSetting, false);
|
||||
if (setting?.allowAdminViewCerts !== true) {
|
||||
throw new PermissionException("该流水线的用户还未授权管理员下载证书,请先让用户在”设置->授权委托“中打开开关");
|
||||
}
|
||||
}
|
||||
|
||||
const privateVars = await this.storeService.getPipelinePrivateVars(id);
|
||||
const certInfo = privateVars.cert;
|
||||
if (!certInfo?.crt) {
|
||||
throw new Error("该流水线还未生成证书,请先运行一次流水线");
|
||||
}
|
||||
|
||||
const certReader = new CertReader(certInfo);
|
||||
const zipBuffer = await certReader.buildZip();
|
||||
const filename = certReader.buildZipFilename("cert");
|
||||
|
||||
logger.info(`download pipeline cert zip: ${filename}, size: ${zipBuffer.length}`);
|
||||
|
||||
this.ctx.attachment(filename);
|
||||
this.ctx.set("Content-Type", "application/zip");
|
||||
this.ctx.body = zipBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user