perf: 支持批量转移流水线到其他项目

This commit is contained in:
xiaojunnuo
2026-03-15 04:17:40 +08:00
parent f642e42eea
commit 8a3841f638
13 changed files with 283 additions and 36 deletions
@@ -7,8 +7,12 @@ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
export class AccessEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'key_id', comment: 'key_id', length: 100 })
keyId: string;
@Column({ name: 'user_id', comment: '用户id' })
userId: number; // 0为系统级别, -1为企业,大于1为用户
@Column({ comment: '名称', length: 100 })
name: string;
@@ -5,6 +5,7 @@ import {AccessGetter, BaseService, PageReq, PermissionException, ValidateExcepti
import {AccessEntity} from '../entity/access.js';
import {AccessDefine, accessRegistry, newAccess} from '@certd/pipeline';
import {EncryptService} from './encrypt-service.js';
import { logger, utils } from '@certd/basic';
/**
* 授权
@@ -46,6 +47,7 @@ export class AccessService extends BaseService<AccessEntity> {
}
delete param._copyFrom
this.encryptSetting(param, oldEntity);
param.keyId = "ac_" + utils.id.simpleNanoId();
return await super.add(param);
}
@@ -117,6 +119,7 @@ export class AccessService extends BaseService<AccessEntity> {
throw new ValidateException('该授权配置不存在,请确认是否已被删除');
}
this.encryptSetting(param, oldEntity);
delete param.keyId
return await super.update(param);
}
@@ -215,4 +218,36 @@ export class AccessService extends BaseService<AccessEntity> {
});
}
/**
* 复制授权到其他项目
* @param accessId
* @param projectId
*/
async copyTo(accessId: number,projectId?: number) {
const access = await this.info(accessId);
if (access == null) {
throw new Error(`该授权配置不存在,请确认是否已被删除:id=${accessId}`);
}
const keyId = access.keyId;
//检查目标项目里是否已经有相同keyId的配置
const existAccess = await this.repository.findOne({
where: {
keyId,
projectId,
},
});
if (existAccess) {
logger.info(`目标项目已存在相同keyId的授权配置,跳过复制:keyId=${keyId}`);
return existAccess.id;
}
const newAccess = {
...access,
id: undefined,
projectId,
}
await this.add(newAccess);
return newAccess.id;
}
}
@@ -6,6 +6,8 @@ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
export class AddonEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'key_id', comment: 'key_id', length: 100 })
keyId: string;
@Column({ name: 'user_id', comment: '用户id' })
userId: number;
@Column({ comment: '名称', length: 100 })
@@ -4,6 +4,7 @@ import { In, Repository } from "typeorm";
import { AddonDefine, BaseService, PageReq, ValidateException } from "../../../index.js";
import { addonRegistry } from "../api/index.js";
import { AddonEntity } from "../entity/addon.js";
import { utils } from "@certd/basic";
/**
* Addon
@@ -43,6 +44,7 @@ export class AddonService extends BaseService<AddonEntity> {
} else {
param.isSystem = false;
}
param.keyId = "ad_" + utils.id.simpleNanoId();
delete param._copyFrom;
return await super.add(param);
}
@@ -57,6 +59,7 @@ export class AddonService extends BaseService<AddonEntity> {
if (oldEntity == null) {
throw new ValidateException("该Addon配置不存在,请确认是否已被删除");
}
delete param.keyId
return await super.update(param);
}
@@ -67,6 +70,7 @@ export class AddonService extends BaseService<AddonEntity> {
}
return {
id: entity.id,
keyId: entity.keyId,
name: entity.name,
userId: entity.userId,
addonType: entity.addonType,
@@ -100,6 +104,7 @@ export class AddonService extends BaseService<AddonEntity> {
},
select: {
id: true,
keyId: true,
name: true,
addonType: true,
type: true,
@@ -132,6 +137,7 @@ export class AddonService extends BaseService<AddonEntity> {
const setting = JSON.parse(res.setting);
return {
id: res.id,
keyId: res.keyId,
addonType: res.addonType,
type: res.type,
name: res.name,