mirror of
https://github.com/certd/certd.git
synced 2026-05-16 21:27:34 +08:00
chore: project
This commit is contained in:
@@ -27,10 +27,10 @@ export class CertInfoFacade {
|
||||
@Inject()
|
||||
userSettingsService : UserSettingsService
|
||||
|
||||
async getCertInfo(req: { domains?: string; certId?: number; userId: number,autoApply?:boolean,format?:string }) {
|
||||
const { domains, certId, userId } = req;
|
||||
async getCertInfo(req: { domains?: string; certId?: number; userId: number, projectId:number, autoApply?:boolean,format?:string }) {
|
||||
const { domains, certId, userId,projectId } = req;
|
||||
if (certId) {
|
||||
return await this.certInfoService.getCertInfoById({ id: certId, userId });
|
||||
return await this.certInfoService.getCertInfoById({ id: certId, userId, projectId });
|
||||
}
|
||||
if (!domains) {
|
||||
throw new CodeException({
|
||||
@@ -69,7 +69,7 @@ export class CertInfoFacade {
|
||||
}
|
||||
}
|
||||
|
||||
return await this.certInfoService.getCertInfoById({ id: matched.id, userId: userId,format:req.format });
|
||||
return await this.certInfoService.getCertInfoById({ id: matched.id, userId: userId,projectId,format:req.format });
|
||||
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ export class CertInfoFacade {
|
||||
}
|
||||
}
|
||||
|
||||
const userEmailSetting = await this.userSettingsService.getSetting<UserEmailSetting>(req.userId,UserEmailSetting)
|
||||
const userEmailSetting = await this.userSettingsService.getSetting<UserEmailSetting>(req.userId,null, UserEmailSetting)
|
||||
if(!userEmailSetting.list){
|
||||
throw new CodeException(Constants.res.openEmailNotFound)
|
||||
}
|
||||
@@ -134,7 +134,7 @@ export class CertInfoFacade {
|
||||
domains: req.domains,
|
||||
email,
|
||||
userId: req.userId,
|
||||
from:"OpenAPI"
|
||||
from: "OpenAPI"
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ export type UploadCertReq = {
|
||||
certReader: CertReader;
|
||||
fromType?: string;
|
||||
userId?: number;
|
||||
projectId?: number;
|
||||
file?:any
|
||||
};
|
||||
|
||||
@@ -113,9 +114,12 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
});
|
||||
}
|
||||
|
||||
async getCertInfoById(req: { id: number; userId: number,format?:string }) {
|
||||
async getCertInfoById(req: { id: number; userId: number,projectId:number,format?:string }) {
|
||||
const entity = await this.info(req.id);
|
||||
if (!entity || entity.userId !== req.userId) {
|
||||
if (!entity || entity.userId !== req.userId ) {
|
||||
throw new CodeException(Constants.res.openCertNotFound);
|
||||
}
|
||||
if (req.projectId && entity.projectId !== req.projectId) {
|
||||
throw new CodeException(Constants.res.openCertNotFound);
|
||||
}
|
||||
|
||||
@@ -167,7 +171,8 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
|
||||
bean.effectiveTime = certReader.effective;
|
||||
bean.expiresTime = certReader.expires;
|
||||
bean.certProvider = certReader.detail.issuer.commonName;
|
||||
bean.userId = userId
|
||||
bean.userId = userId;
|
||||
bean.projectId = req.projectId;
|
||||
if(req.file){
|
||||
bean.certFile = req.file
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
throw new Error("站点域名不能为空");
|
||||
}
|
||||
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(site.userId, UserSiteMonitorSetting);
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(site.userId,site.projectId, UserSiteMonitorSetting);
|
||||
const dnsServer = setting.dnsServer
|
||||
let customDns = null
|
||||
if (dnsServer && dnsServer.length > 0) {
|
||||
@@ -162,7 +162,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
}
|
||||
await this.update(updateData);
|
||||
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(site.userId, UserSiteMonitorSetting)
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(site.userId,site.projectId, UserSiteMonitorSetting)
|
||||
//检查ip
|
||||
await this.checkAllIp(site,retryTimes,setting);
|
||||
|
||||
@@ -356,16 +356,17 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
|
||||
async checkList(sites: SiteInfoEntity[],isCommon: boolean) {
|
||||
const cache = {}
|
||||
const getFromCache = async (userId: number) =>{
|
||||
if (cache[userId]) {
|
||||
return cache[userId];
|
||||
const getFromCache = async (userId: number,projectId?: number) =>{
|
||||
const key = `${userId}-${projectId??""}`
|
||||
if (cache[key]) {
|
||||
return cache[key];
|
||||
}
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(userId, UserSiteMonitorSetting)
|
||||
cache[userId] = setting
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(userId,projectId, UserSiteMonitorSetting)
|
||||
cache[key] = setting
|
||||
return setting;
|
||||
}
|
||||
for (const site of sites) {
|
||||
const setting = await getFromCache(site.userId)
|
||||
const setting = await getFromCache(site.userId,site.projectId)
|
||||
if (isCommon) {
|
||||
//公共的检查,排除有设置cron的用户
|
||||
if (setting?.cron) {
|
||||
@@ -381,17 +382,17 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
async getSetting(userId: number) {
|
||||
return await this.userSettingsService.getSetting<UserSiteMonitorSetting>(userId, UserSiteMonitorSetting);
|
||||
async getSetting(userId: number,projectId?: number) {
|
||||
return await this.userSettingsService.getSetting<UserSiteMonitorSetting>(userId,projectId, UserSiteMonitorSetting);
|
||||
}
|
||||
|
||||
async saveSetting(userId: number, bean: UserSiteMonitorSetting) {
|
||||
await this.userSettingsService.saveSetting(userId, bean);
|
||||
async saveSetting(userId: number,projectId: number, bean: UserSiteMonitorSetting) {
|
||||
await this.userSettingsService.saveSetting(userId,projectId, bean);
|
||||
if(bean.cron){
|
||||
//注册job
|
||||
await this.registerSiteMonitorJob(userId);
|
||||
await this.registerSiteMonitorJob(userId,projectId);
|
||||
}else{
|
||||
this.clearSiteMonitorJob(userId);
|
||||
this.clearSiteMonitorJob(userId,projectId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,13 +477,13 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
await batchAdd(list);
|
||||
}
|
||||
|
||||
clearSiteMonitorJob(userId: number) {
|
||||
this.cron.remove(`siteMonitor-${userId}`);
|
||||
clearSiteMonitorJob(userId: number,projectId?: number) {
|
||||
this.cron.remove(`siteMonitor-${userId}-${projectId||""}`);
|
||||
}
|
||||
|
||||
async registerSiteMonitorJob(userId?: number) {
|
||||
async registerSiteMonitorJob(userId?: number,projectId?: number) {
|
||||
|
||||
if(!userId){
|
||||
if(userId == null){
|
||||
//注册公共job
|
||||
logger.info(`注册站点证书检查定时任务`)
|
||||
this.cron.register({
|
||||
@@ -494,27 +495,30 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
});
|
||||
logger.info(`注册站点证书检查定时任务完成`)
|
||||
}else{
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(userId, UserSiteMonitorSetting);
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(userId,projectId, UserSiteMonitorSetting);
|
||||
if (!setting.cron) {
|
||||
return;
|
||||
}
|
||||
//注册个人的
|
||||
//注册个人的 或项目的
|
||||
this.cron.register({
|
||||
name: `siteMonitor-${userId}`,
|
||||
name: `siteMonitor-${userId}-${projectId||""}`,
|
||||
cron: setting.cron,
|
||||
job: () => this.triggerJobOnce(userId),
|
||||
job: () => this.triggerJobOnce(userId,projectId),
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async triggerJobOnce(userId?:number) {
|
||||
logger.info(`站点证书检查开始执行[${userId??'所有用户'}]`);
|
||||
async triggerJobOnce(userId?:number,projectId?:number) {
|
||||
logger.info(`站点证书检查开始执行[${userId??'所有用户'}-${projectId??'所有项目'}]`);
|
||||
const query:any = { disabled: false };
|
||||
if(userId){
|
||||
query.userId = userId;
|
||||
if(projectId){
|
||||
query.projectId = projectId;
|
||||
}
|
||||
//判断是否已关闭
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(userId, UserSiteMonitorSetting);
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(userId,projectId, UserSiteMonitorSetting);
|
||||
if (!setting.cron) {
|
||||
return;
|
||||
}
|
||||
@@ -536,7 +540,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
await this.checkList(records,isCommon);
|
||||
}
|
||||
|
||||
logger.info(`站点证书检查完成[${userId??'所有用户'}]`);
|
||||
logger.info(`站点证书检查完成[${userId??'所有用户'}-${projectId??'所有项目'}]`);
|
||||
}
|
||||
|
||||
async batchDelete(ids: number[], userId: number,projectId?:number): Promise<void> {
|
||||
|
||||
@@ -67,7 +67,7 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
||||
|
||||
const domain = entity.domain;
|
||||
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(entity.userId, UserSiteMonitorSetting);
|
||||
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(entity.userId,entity.projectId, UserSiteMonitorSetting);
|
||||
|
||||
const dnsServer = setting.dnsServer
|
||||
let resolver = dns
|
||||
|
||||
Reference in New Issue
Block a user