perf: 手动上传证书部署流水线

This commit is contained in:
xiaojunnuo
2025-03-22 02:06:02 +08:00
parent fedf90ea78
commit fbb66f3c43
25 changed files with 329 additions and 511 deletions

View File

@@ -1,11 +1,11 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController } from '@certd/lib-server';
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
import { CertInfoService } from '../../../modules/monitor/index.js';
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
import { ALL, Body, Controller, Get, Inject, Post, Provide, Query } from "@midwayjs/core";
import { CommonException, Constants, CrudController } from "@certd/lib-server";
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
import { CertInfoService } from "../../../modules/monitor/index.js";
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
import { SelectQueryBuilder } from "typeorm";
import { CertUploadService } from "../../../modules/monitor/service/cert-upload-service.js";
import { CertInfo } from "@certd/plugin-cert";
import { logger } from "@certd/basic";
import fs from "fs";
/**
*/
@@ -17,8 +17,6 @@ export class CertInfoController extends CrudController<CertInfoService> {
@Inject()
authService: AuthService;
@Inject()
certUploadService: CertUploadService;
@Inject()
pipelineService: PipelineService;
getService(): CertInfoService {
@@ -131,26 +129,28 @@ export class CertInfoController extends CrudController<CertInfoService> {
return this.ok(certInfo);
}
@Post('/upload', { summary: Constants.per.authOnly })
async upload(@Body(ALL) body: {cert: CertInfo, pipeline: any, id?: number}) {
if (body.id) {
//修改
await this.service.checkUserId(body.id, this.getUserId());
await this.certUploadService.updateCert({
id: body.id,
userId: this.getUserId(),
cert: body.cert,
});
return this.ok();
}else{
//添加
const res = await this.certUploadService.createUploadCertPipeline({
userId: this.getUserId(),
cert: body.cert,
pipeline: body.pipeline,
});
return this.ok(res)
@Get('/download', { summary: Constants.per.authOnly })
async download(@Query('id') id: number) {
const certInfo = await this.service.info(id)
if (certInfo == null) {
throw new CommonException('file not found');
}
if (certInfo.userId !== this.getUserId()) {
throw new CommonException('file not found');
}
// koa send file
// 下载文件的名称
// const filename = file.filename;
// 要下载的文件的完整路径
const path = certInfo.certFile;
if (!path) {
throw new CommonException('file not found');
}
logger.info(`download:${path}`);
// 以流的形式下载文件
this.ctx.attachment(path);
this.ctx.set('Content-Type', 'application/octet-stream');
return fs.createReadStream(path);
}
}

View File

@@ -13,7 +13,6 @@ import {
import {EmailService} from '../../../modules/basic/service/email-service.js';
import {http, HttpRequestConfig, logger, mergeUtils, utils} from '@certd/basic';
import {NotificationService} from '../../../modules/pipeline/service/notification-service.js';
import {CertApplyUploadService} from "../../../modules/pipeline/service/cert-apply-upload-service.js";
@Provide()
@Controller('/api/pi/handle')
@@ -24,8 +23,6 @@ export class HandleController extends BaseController {
@Inject()
emailService: EmailService;
@Inject()
certApplyUploadService: CertApplyUploadService;
@Inject()
notificationService: NotificationService;
@@ -97,7 +94,6 @@ export class HandleController extends BaseController {
};
const serviceContainer:any = {
CertApplyUploadService:this.certApplyUploadService
}
const serviceGetter = {
get:(name: string) => {