Skip to content

Commit d62b52f

Browse files
committed
feat: integrate XrayService into HandlerService for user management
- Added XrayModule to HandlerModule imports for dependency injection. - Enhanced HandlerService to utilize XrayService for retrieving inbound tags. - Updated addUser method to remove users from tags using XrayService.
1 parent 1369f79 commit d62b52f

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/modules/handler/handler.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Module } from '@nestjs/common';
22

33
import { HandlerController } from './handler.controller';
4+
import { XrayModule } from '../xray-core/xray.module';
45
import { HandlerService } from './handler.service';
5-
66
@Module({
7-
imports: [],
7+
imports: [XrayModule],
88
controllers: [HandlerController],
99
providers: [HandlerService],
1010
})

src/modules/handler/handler.service.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,31 @@ import { ERRORS } from '@libs/contracts/constants/errors';
1212
import { AddUserResponseModel, RemoveUserResponseModel } from './models';
1313
import { GetInboundUsersCountResponseModel } from './models';
1414
import { GetInboundUsersResponseModel } from './models';
15+
import { XrayService } from '../xray-core/xray.service';
1516
import { IRemoveUserRequest } from './interfaces';
1617
import { TAddUserRequest } from './interfaces';
1718

1819
@Injectable()
1920
export class HandlerService {
2021
private readonly logger = new Logger(HandlerService.name);
2122

22-
constructor(@InjectXtls() private readonly xtlsApi: XtlsApi) {}
23+
constructor(
24+
@InjectXtls() private readonly xtlsApi: XtlsApi,
25+
private readonly xrayService: XrayService,
26+
) {}
2327

2428
public async addUser(data: TAddUserRequest): Promise<ICommandResponse<AddUserResponseModel>> {
2529
try {
2630
const { data: requestData } = data;
2731
const response: Array<ISdkResponse<AddUserResponseModelFromSdk>> = [];
2832

33+
const inboundsTags = this.xrayService.getSavedInboundsTags();
34+
35+
for (const tag of inboundsTags) {
36+
this.logger.debug(`Removing user: ${requestData[0].username} from tag: ${tag}`);
37+
await this.xtlsApi.handler.removeUser(tag, requestData[0].username);
38+
}
39+
2940
for (const item of requestData) {
3041
let tempRes = null;
3142

src/modules/xray-core/xray.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { XrayService } from './xray.service';
88
imports: [InternalModule],
99
providers: [XrayService],
1010
controllers: [XrayController],
11-
exports: [],
11+
exports: [XrayService],
1212
})
1313
export class XrayModule implements OnModuleDestroy {
1414
constructor(private readonly xrayService: XrayService) {}

src/modules/xray-core/xray.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,8 @@ export class XrayService implements OnApplicationBootstrap, OnModuleInit {
451451

452452
return config.inbounds.map((inbound: { tag: string }) => inbound.tag);
453453
}
454+
455+
public getSavedInboundsTags(): string[] {
456+
return this.xtlsConfigInbounds;
457+
}
454458
}

0 commit comments

Comments
 (0)