mirror of
https://github.com/certd/certd.git
synced 2026-06-30 16:39:43 +08:00
perf: 商业版支持限制泛域名数量
This commit is contained in:
@@ -18,6 +18,9 @@ export class CertInfoEntity {
|
||||
@Column({ name: 'domain_count', comment: '域名数量' })
|
||||
domainCount: number;
|
||||
|
||||
@Column({ name: 'wildcard_domain_count', comment: '泛域名数量', default: 0 })
|
||||
wildcardDomainCount: number;
|
||||
|
||||
@Column({ name: 'pipeline_id', comment: '关联流水线id' })
|
||||
pipelineId: number;
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import assert from "assert";
|
||||
import { CertInfoService } from "./cert-info-service.js";
|
||||
|
||||
describe("CertInfoService", () => {
|
||||
it("counts wildcard domains by normalized prefix", () => {
|
||||
const service = new CertInfoService();
|
||||
|
||||
assert.equal(service.countWildcardDomains(["*.a.com", "a.com", " *.B.com "]), 2);
|
||||
});
|
||||
|
||||
it("saves wildcard domain count when updating pipeline domains", async () => {
|
||||
const service = new CertInfoService();
|
||||
let saved: any;
|
||||
service.repository = {
|
||||
async findOne() {
|
||||
return null;
|
||||
},
|
||||
} as any;
|
||||
service.addOrUpdate = async (bean: any) => {
|
||||
saved = bean;
|
||||
return bean;
|
||||
};
|
||||
|
||||
await service.updateDomains(1, 2, null, ["*.a.com", "a.com", "*.b.com"], "pipeline");
|
||||
|
||||
assert.equal(saved.domainCount, 3);
|
||||
assert.equal(saved.wildcardDomainCount, 2);
|
||||
});
|
||||
});
|
||||
@@ -40,6 +40,22 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
});
|
||||
}
|
||||
|
||||
async getUserWildcardDomainCount(userId: number) {
|
||||
if (userId == null) {
|
||||
throw new Error('userId is required');
|
||||
}
|
||||
return await this.repository.sum('wildcardDomainCount', {
|
||||
userId,
|
||||
});
|
||||
}
|
||||
|
||||
countWildcardDomains(domains?: string[]) {
|
||||
if (!domains) {
|
||||
return 0;
|
||||
}
|
||||
return domains.filter(domain => domain?.trim().toLowerCase().startsWith("*.")).length;
|
||||
}
|
||||
|
||||
async updateDomains(pipelineId: number, userId: number, projectId: number, domains: string[],fromType?:string) {
|
||||
const found = await this.repository.findOne({
|
||||
where: {
|
||||
@@ -67,10 +83,12 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
bean.domain = '';
|
||||
bean.domains = '';
|
||||
bean.domainCount = 0;
|
||||
bean.wildcardDomainCount = 0;
|
||||
} else {
|
||||
bean.domain = domains[0];
|
||||
bean.domains = domains.join(',');
|
||||
bean.domainCount = domains.length;
|
||||
bean.wildcardDomainCount = this.countWildcardDomains(domains);
|
||||
}
|
||||
|
||||
await this.addOrUpdate(bean);
|
||||
@@ -171,6 +189,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
bean.domains = domains.join(',');
|
||||
bean.domain = domains[0];
|
||||
bean.domainCount = domains.length;
|
||||
bean.wildcardDomainCount = this.countWildcardDomains(domains);
|
||||
bean.effectiveTime = certReader.effective;
|
||||
bean.expiresTime = certReader.expires;
|
||||
bean.certProvider = certReader.detail.issuer.commonName;
|
||||
|
||||
Reference in New Issue
Block a user