fix: api接口获取不到证书的bug

v2
xiaojunnuo 2025-07-18 14:46:58 +08:00
parent 747d266742
commit 05a33a0ec9
2 changed files with 33 additions and 5 deletions

View File

@ -32,6 +32,12 @@ export class CertInfoFacade {
if (certId) {
return await this.certInfoService.getCertInfoById({ id: certId, userId });
}
if (!domains) {
throw new CodeException({
...Constants.res.openParamError,
message: "参数错误certId和domains必须传一个",
});
}
const domainArr = domains.split(',');
const matchedList = await this.certInfoService.getMatchCertList({domains:domainArr,userId})
@ -42,12 +48,15 @@ export class CertInfoFacade {
const pipeline:PipelineEntity = await this.createAutoPipeline({domains:domainArr,userId})
await this.triggerApplyPipeline({pipelineId:pipeline.id})
}else{
throw new CodeException(Constants.res.openCertNotFound);
throw new CodeException({
...Constants.res.openCertNotFound,
message:"在证书仓库中没有找到匹配域名的证书请先创建证书流水线或传入autoApply参数自动创建"
});
}
}
matched = null;
for (const item of matchedList) {
if (item.expiresTime>0 && item.expiresTime < new Date().getTime()) {
if (item.expiresTime>0 && item.expiresTime > new Date().getTime()) {
matched = item;
break
}
@ -59,7 +68,10 @@ export class CertInfoFacade {
await this.triggerApplyPipeline({pipelineId:first.pipelineId})
return
}else{
throw new CodeException(Constants.res.openCertNotFound);
throw new CodeException({
...Constants.res.openCertNotFound,
message:"证书已过期请触发流水线申请或者传入autoApply参数自动触发"
});
}
}
@ -109,10 +121,12 @@ export class CertInfoFacade {
await this.pipelineService.trigger(req.pipelineId)
await utils.sleep(1000)
}
const certInfo = await this.certInfoService.getByPipelineId(req.pipelineId)
throw new CodeException({
...Constants.res.openCertApplying,
data:{
pipelineId:req.pipelineId
pipelineId:req.pipelineId,
certId:certInfo?.id
}
});
}

View File

@ -86,7 +86,10 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
async getMatchCertList(params: { domains: string[]; userId: number }) {
const { domains, userId } = params;
if (!domains) {
throw new CodeException(Constants.res.openCertNotFound);
throw new CodeException({
...Constants.res.openCertNotFound,
message:"域名不能为空"
});
}
const list = await this.find({
@ -99,6 +102,9 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
where: {
userId,
},
order: {
id: 'DESC',
},
});
//遍历查找
return list.filter(item => {
@ -161,4 +167,12 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
return bean;
}
async getByPipelineId(pipelineId: number) {
return await this.repository.findOne({
where: {
pipelineId,
},
});
}
}