mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
feat: 支持open api接口,根据域名获取证书
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
export * from "./entity/site-info.js";
|
||||
export * from "./entity/cert-info.js";
|
||||
|
||||
export * from "./service/cert-info-service.js";
|
||||
export * from "./service/site-info-service.js";
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Provide } from '@midwayjs/core';
|
||||
import { BaseService, PageReq } from '@certd/lib-server';
|
||||
import { BaseService, CodeException, Constants, PageReq } from '@certd/lib-server';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CertInfoEntity } from '../entity/cert-info.js';
|
||||
import { utils } from '@certd/basic';
|
||||
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
||||
|
||||
@Provide()
|
||||
export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
@@ -68,4 +70,25 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
pipelineId: id,
|
||||
});
|
||||
}
|
||||
|
||||
async getCertInfo(param: { domains: string[]; userId: number }) {
|
||||
const { domains, userId } = param;
|
||||
|
||||
const list = await this.find({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
});
|
||||
//遍历查找
|
||||
const matched = list.find(item => {
|
||||
const itemDomains = item.domains.split(',');
|
||||
return utils.domain.match(domains, itemDomains);
|
||||
});
|
||||
if (!matched || !matched.certInfo) {
|
||||
throw new CodeException(Constants.res.openCertNotFound);
|
||||
}
|
||||
const certInfo = JSON.parse(matched.certInfo) as CertInfo;
|
||||
const certReader = new CertReader(certInfo);
|
||||
return certReader.toCertInfo();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user