feat: 站点证书监控

This commit is contained in:
xiaojunnuo
2024-12-22 14:01:10 +08:00
parent a019956698
commit 9c8c7a7812
4 changed files with 150 additions and 7 deletions
@@ -0,0 +1,47 @@
import { Provide } from '@midwayjs/core';
import { BaseService } from '@certd/lib-server';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { CertInfoEntity } from '../entity/cert-info.js';
@Provide()
export class CertInfoService extends BaseService<CertInfoEntity> {
@InjectEntityModel(CertInfoEntity)
repository: Repository<CertInfoEntity>;
//@ts-ignore
getRepository() {
return this.repository;
}
async getUserDomainCount(userId: number) {
if (!userId) {
throw new Error('userId is required');
}
return await this.repository.sum('domainCount', {
userId,
});
}
async updateDomains(pipelineId: number, domains: string[]) {
const found = await this.repository.findOne({
where: {
pipelineId,
},
});
const bean = new CertInfoEntity();
if (found) {
//bean
bean.id = found.id;
} else {
//create
bean.pipelineId = pipelineId;
}
bean.domain = domains[0];
bean.domains = domains.join(',');
bean.domainCount = domains.length;
await this.addOrUpdate(bean);
}
}
@@ -0,0 +1,25 @@
import { Provide } from '@midwayjs/core';
import { BaseService } from '@certd/lib-server';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { SiteInfoEntity } from '../entity/site-info.js';
@Provide()
export class SiteInfoService extends BaseService<SiteInfoEntity> {
@InjectEntityModel(SiteInfoEntity)
repository: Repository<SiteInfoEntity>;
//@ts-ignore
getRepository() {
return this.repository;
}
async getUserMonitorCount(userId: number) {
if (!userId) {
throw new Error('userId is required');
}
return await this.repository.count({
where: { userId },
});
}
}