Skip to content

Commit 30d8293

Browse files
committed
feat: add reserved name errors for config profiles and internal squads
- Introduced error handling for reserved names in ConfigProfileService and InternalSquadService. - Added new error constants for 'Default-Profile' and 'Default-Squad' in the errors module. - Enhanced seeding logic to handle existing internal squads and config profile inbounds.
1 parent 6c11ce0 commit 30d8293

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

libs/contract/constants/errors/errors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,4 +714,14 @@ export const ERRORS = {
714714
message: 'Delete config profile by UUID error',
715715
httpCode: 500,
716716
},
717+
RESERVED_INTERNAL_SQUAD_NAME: {
718+
code: 'A144',
719+
message: 'This name is reserved by Remnawave. Please use a different name.',
720+
httpCode: 400,
721+
},
722+
RESERVED_CONFIG_PROFILE_NAME: {
723+
code: 'A145',
724+
message: 'This name is reserved by Remnawave. Please use a different name.',
725+
httpCode: 400,
726+
},
717727
} as const;

prisma/seed/config.seed.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,20 +671,52 @@ async function seedDefaultConfigProfile() {
671671
process.exit(1);
672672
}
673673

674+
await syncInbounds();
675+
676+
const existingInternalSquad = await prisma.internalSquads.findFirst();
677+
678+
// workaround for created squad from migration
679+
if (existingInternalSquad && existingInternalSquad.name === 'Default-Squad') {
680+
const configProfileInbounds = await prisma.configProfileInbounds.findMany({
681+
where: {
682+
profileUuid: config.uuid,
683+
},
684+
});
685+
686+
if (configProfileInbounds.length === 0) {
687+
consola.info('🔐 No config profile inbounds found!');
688+
return;
689+
}
690+
691+
const internalSquadInbounds = await prisma.internalSquadInbounds.createMany({
692+
data: configProfileInbounds.map((inbound) => ({
693+
inboundUuid: inbound.uuid,
694+
internalSquadUuid: existingInternalSquad.uuid,
695+
})),
696+
});
697+
698+
if (!internalSquadInbounds) {
699+
consola.error('🔐 Failed to create default internal squad inbounds!');
700+
process.exit(1);
701+
}
702+
703+
return;
704+
}
705+
674706
consola.success('🔐 Default config profile seeded!');
675707
}
676708

677709
async function seedDefaultInternalSquad() {
678-
const existingConfig = await prisma.internalSquads.findFirst();
710+
const existingInternalSquad = await prisma.internalSquads.findFirst();
679711
const existingConfigProfile = await prisma.configProfiles.findFirst();
680712

681713
if (!existingConfigProfile) {
682714
consola.error('🔐 Default config profile not found!');
683715
process.exit(1);
684716
}
685717

686-
if (existingConfig) {
687-
consola.info('Default internal subscription already seeded!');
718+
if (existingInternalSquad) {
719+
consola.info('🤔 Default internal squad already exists!');
688720
return;
689721
}
690722

src/modules/config-profiles/config-profile.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ export class ConfigProfileService {
122122
config: object,
123123
): Promise<ICommandResponse<GetConfigProfileByUuidResponseModel>> {
124124
try {
125+
if (name === 'Default-Profile') {
126+
return {
127+
isOk: false,
128+
...ERRORS.RESERVED_CONFIG_PROFILE_NAME,
129+
};
130+
}
131+
125132
const validatedConfig = new XRayConfig(config);
126133
const sortedConfig = validatedConfig.getSortedConfig();
127134

src/modules/internal-squads/internal-squad.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ export class InternalSquadService {
7575
inbounds: string[],
7676
): Promise<ICommandResponse<GetInternalSquadByUuidResponseModel>> {
7777
try {
78+
if (name === 'Default-Squad') {
79+
return {
80+
isOk: false,
81+
...ERRORS.RESERVED_INTERNAL_SQUAD_NAME,
82+
};
83+
}
84+
7885
const internalSquad = await this.internalSquadRepository.create(
7986
new InternalSquadEntity({
8087
name,

0 commit comments

Comments
 (0)