mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
feat: 基础版不再限制流水线数量
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ import crypto from 'crypto';
|
||||
|
||||
@Autoload()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class AutoInitSite {
|
||||
export class AutoAInitSite {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import { Cron } from '../cron/cron.js';
|
||||
|
||||
@Autoload()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class AutoRegisterCron {
|
||||
export class AutoCRegisterCron {
|
||||
@Inject()
|
||||
pipelineService: PipelineService;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { logger, utils } from '@certd/basic';
|
||||
import { UserSuiteService } from '@certd/commercial-core';
|
||||
import { Autoload, Init, Inject, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
|
||||
@Autoload()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class AutoDMitterRegister {
|
||||
@Inject()
|
||||
userSuiteService: UserSuiteService;
|
||||
|
||||
@Init()
|
||||
async init() {
|
||||
await this.registerOnNewUser();
|
||||
}
|
||||
async registerOnNewUser() {
|
||||
utils.mitter.on('register', async (req: { userId: number }) => {
|
||||
logger.info('register event', req.userId);
|
||||
await this.userSuiteService.presentGiftSuite(req.userId);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,9 @@ export class AutoZPrint {
|
||||
async init() {
|
||||
//监听https
|
||||
this.startHttpsServer();
|
||||
|
||||
if (isDev()) {
|
||||
this.startHeapLog();
|
||||
}
|
||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||
logger.info('=========================================');
|
||||
logger.info('当前站点ID:', installInfo.siteId);
|
||||
@@ -36,9 +38,6 @@ export class AutoZPrint {
|
||||
}
|
||||
logger.info('Certd已启动');
|
||||
logger.info('=========================================');
|
||||
if (isDev()) {
|
||||
this.startHeapLog();
|
||||
}
|
||||
}
|
||||
|
||||
startHeapLog() {
|
||||
@@ -50,7 +49,7 @@ export class AutoZPrint {
|
||||
}, 60000);
|
||||
}
|
||||
|
||||
async startHttpsServer() {
|
||||
startHttpsServer() {
|
||||
if (!this.httpsConfig.enabled) {
|
||||
logger.info('Https server is not enabled');
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Inject, Provide } from '@midwayjs/core';
|
||||
import { BaseService } from '@certd/lib-server';
|
||||
import { BaseService, NeedSuiteException, NeedVIPException, SysSettingsService, SysSuiteSetting } from '@certd/lib-server';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { SiteInfoEntity } from '../entity/site-info.js';
|
||||
@@ -8,6 +8,8 @@ import dayjs from 'dayjs';
|
||||
import { logger } from '@certd/basic';
|
||||
import { PeerCertificate } from 'tls';
|
||||
import { NotificationService } from '../../pipeline/service/notification-service.js';
|
||||
import { isComm, isPlus } from '@certd/plus-core';
|
||||
import { UserSuiteService } from '@certd/commercial-core';
|
||||
|
||||
@Provide()
|
||||
export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
@@ -17,11 +19,41 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
@Inject()
|
||||
notificationService: NotificationService;
|
||||
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
|
||||
@Inject()
|
||||
userSuiteService: UserSuiteService;
|
||||
|
||||
//@ts-ignore
|
||||
getRepository() {
|
||||
return this.repository;
|
||||
}
|
||||
|
||||
async add(data: SiteInfoEntity) {
|
||||
if (!data.userId) {
|
||||
throw new Error('userId is required');
|
||||
}
|
||||
|
||||
if (!isPlus()) {
|
||||
const count = await this.getUserMonitorCount(data.userId);
|
||||
if (count >= 1) {
|
||||
throw new NeedVIPException('站点监控数量已达上限,请升级专业版');
|
||||
}
|
||||
}
|
||||
if (isComm()) {
|
||||
const suiteSetting = await this.sysSettingsService.getSetting<SysSuiteSetting>(SysSuiteSetting);
|
||||
if (suiteSetting.enabled) {
|
||||
const userSuite = await this.userSuiteService.getMySuiteDetail(data.userId);
|
||||
if (userSuite.monitorCount.max != -1 && userSuite.monitorCount.max <= userSuite.monitorCount.used) {
|
||||
throw new NeedSuiteException('站点监控数量已达上限,请购买或升级套餐');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await this.repository.save(data);
|
||||
}
|
||||
|
||||
async getUserMonitorCount(userId: number) {
|
||||
if (!userId) {
|
||||
throw new Error('userId is required');
|
||||
|
||||
@@ -205,11 +205,11 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
if (isComm()) {
|
||||
//校验pipelineCount
|
||||
const userSuite = await this.userSuiteService.getMySuiteDetail(bean.userId);
|
||||
if (userSuite?.pipelineCount.used + 1 > userSuite?.pipelineCount.max) {
|
||||
if (userSuite?.pipelineCount.max != -1 && userSuite?.pipelineCount.used + 1 > userSuite?.pipelineCount.max) {
|
||||
throw new NeedSuiteException(`对不起,您最多只能创建${userSuite?.pipelineCount.max}条流水线,请购买或升级套餐`);
|
||||
}
|
||||
|
||||
if (userSuite.domainCount.used + domains.length > userSuite.domainCount.max) {
|
||||
if (userSuite.domainCount.max != -1 && userSuite.domainCount.used + domains.length > userSuite.domainCount.max) {
|
||||
throw new NeedSuiteException(`对不起,您最多只能添加${userSuite.domainCount.max}个域名,请购买或升级套餐`);
|
||||
}
|
||||
}
|
||||
@@ -222,7 +222,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
const sysPublic = await this.sysSettingsService.getSetting<SysPublicSettings>(SysPublicSettings);
|
||||
const limitUserPipelineCount = sysPublic.limitUserPipelineCount;
|
||||
if (limitUserPipelineCount && limitUserPipelineCount > 0 && count >= limitUserPipelineCount) {
|
||||
throw new NeedVIPException(`您最多只能创建${limitUserPipelineCount}条流水线`);
|
||||
throw new NeedVIPException(`普通用户最多只能创建${limitUserPipelineCount}条流水线`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user