Merge branch 'v2-dev' of https://github.com/certd/certd into v2-dev

This commit is contained in:
xiaojunnuo
2026-03-12 18:11:09 +08:00
56 changed files with 587 additions and 151 deletions
@@ -16,6 +16,7 @@ import {SiteIpService} from "./site-ip-service.js";
import {SiteIpEntity} from "../entity/site-ip.js";
import {Cron} from "../../cron/cron.js";
import { dnsContainer } from "./dns-custom.js";
import { merge } from "lodash-es";
@Provide()
@Scope(ScopeEnum.Request, {allowDowngrade: true})
@@ -164,6 +165,8 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
await this.update(updateData);
const setting = await this.userSettingsService.getSetting<UserSiteMonitorSetting>(site.userId,site.projectId, UserSiteMonitorSetting)
merge(site,updateData)
//检查ip
await this.checkAllIp(site,retryTimes,setting);
@@ -0,0 +1,93 @@
import { isEnterprise } from "@certd/lib-server";
import { ApplicationContext, IMidwayContainer, Provide, Scope, ScopeEnum } from "@midwayjs/core";
@Provide()
@Scope(ScopeEnum.Request, { allowDowngrade: true })
export class TransferService {
@ApplicationContext()
appCtx: IMidwayContainer;
async getServices() {
const getService = async (key: string) => {
return await this.appCtx.getAsync(key);
}
const serviceNames = [
"pipeline",
"certInfo",
"siteInfo",
"domain",
"cnameRecord",
"group",
"pipelineGroup",
"notification",
"subDomain",
"template",
"openKey",
"siteIp",
"access",
"history",
"historyLog",
"storage",
]
const services: any = {}
for (const key of serviceNames) {
services[key] = await getService(`${key}Service`);
}
return services;
}
/**
* 获取用户资源
* @param userId
* @returns
*/
async getUserResources(userId: number) {
const query = {
userId,
}
const services = await this.getServices();
const counts: any = {}
let totalCount = 0;
for (const key of Object.keys(services)) {
const count = await services[key].repository.count({ where: query });
counts[key] = count;
totalCount += count;
}
return {
...counts,
totalCount,
}
}
async transferAll(userId: number, projectId: number) {
if (!isEnterprise()) {
throw new Error('当前非企业模式,不支持资源迁移到项目');
}
if (projectId === 0) {
throw new Error('项目ID不能为0');
}
if (userId == null) {
throw new Error('用户ID不能为空');
}
const query = {
userId,
}
const services = await this.getServices();
for (const key of Object.keys(services)) {
await services[key].repository.update(query, {
userId: -1,
projectId,
});
}
}
}