@@ -8,21 +8,13 @@ import { CommandBus } from '@nestjs/cqrs';
88
99import {
1010 AddUserCommand ,
11- GetAllInboundsStatsCommand ,
12- GetAllOutboundsStatsCommand ,
13- GetInboundStatsCommand ,
14- GetInboundUsersCommand ,
15- GetInboundUsersCountCommand ,
11+ GetCombinedStatsCommand ,
1612 GetNodeHealthCheckCommand ,
17- GetOutboundStatsCommand ,
1813 GetSystemStatsCommand ,
19- GetUserOnlineStatusCommand ,
2014 GetUsersStatsCommand ,
2115 RemoveUserCommand ,
2216 StartXrayCommand ,
2317 StopXrayCommand ,
24- X_HASH_PAYLOAD ,
25- X_FORCE_RESTART ,
2618} from '@remnawave/node-contract' ;
2719
2820import { GetNodeJwtCommand , IGetNodeJwtResponse } from '@modules/keygen/commands/get-node-jwt' ;
@@ -92,10 +84,8 @@ export class AxiosService {
9284
9385 public async startXray (
9486 data : StartXrayCommand . Request ,
95- hashesPayload : string ,
9687 url : string ,
9788 port : null | number ,
98- force ?: boolean ,
9989 ) : Promise < ICommandResponse < StartXrayCommand . Response > > {
10090 const nodeUrl = this . getNodeUrl ( url , StartXrayCommand . url , port ) ;
10191 try {
@@ -104,10 +94,6 @@ export class AxiosService {
10494 data ,
10595 {
10696 timeout : 60_000 ,
107- headers : {
108- [ X_HASH_PAYLOAD ] : hashesPayload ,
109- [ X_FORCE_RESTART ] : force ? 'true' : 'false' ,
110- } ,
11197 } ,
11298 ) ;
11399
@@ -215,37 +201,6 @@ export class AxiosService {
215201 * STATS MANAGEMENT
216202 */
217203
218- public async getUserOnlineStatus (
219- data : GetUserOnlineStatusCommand . Request ,
220- url : string ,
221- port : null | number ,
222- ) : Promise < ICommandResponse < GetUserOnlineStatusCommand . Response > > {
223- const nodeUrl = this . getNodeUrl ( url , GetUserOnlineStatusCommand . url , port ) ;
224-
225- try {
226- const response = await this . axiosInstance . post < GetUserOnlineStatusCommand . Response > (
227- nodeUrl ,
228- data ,
229- ) ;
230-
231- return {
232- isOk : true ,
233- response : response . data ,
234- } ;
235- } catch ( error ) {
236- if ( error instanceof AxiosError ) {
237- this . logger . error ( 'Error in getUserOnlineStatus:' , error . response ?. data ) ;
238- } else {
239- this . logger . error ( 'Error in getUserOnlineStatus:' , error ) ;
240- }
241-
242- return {
243- isOk : false ,
244- ...ERRORS . INTERNAL_SERVER_ERROR ,
245- } ;
246- }
247- }
248-
249204 public async getUsersStats (
250205 data : GetUsersStatsCommand . Request ,
251206 url : string ,
@@ -334,64 +289,25 @@ export class AxiosService {
334289 }
335290 }
336291
337- public async getInboundStats (
338- data : GetInboundStatsCommand . Request ,
339- url : string ,
340- port : null | number ,
341- ) : Promise < ICommandResponse < GetInboundStatsCommand . Response > > {
342- const nodeUrl = this . getNodeUrl ( url , GetInboundStatsCommand . url , port ) ;
343-
344- try {
345- const response = await this . axiosInstance . post < GetInboundStatsCommand . Response > (
346- nodeUrl ,
347- data ,
348- {
349- timeout : 15_000 ,
350- } ,
351- ) ;
352-
353- return {
354- isOk : true ,
355- response : response . data ,
356- } ;
357- } catch ( error ) {
358- if ( error instanceof AxiosError ) {
359- this . logger . error ( 'Error in getInboundStats:' , error . response ?. data ) ;
360- } else {
361- this . logger . error ( 'Error in getInboundStats:' , error ) ;
362- }
363-
364- return {
365- isOk : false ,
366- ...ERRORS . INTERNAL_SERVER_ERROR ,
367- } ;
368- }
369- }
370-
371- public async getAllInboundStats (
372- data : GetAllInboundsStatsCommand . Request ,
292+ public async getCombinedStats (
293+ data : GetCombinedStatsCommand . Request ,
373294 url : string ,
374295 port : null | number ,
375- ) : Promise < ICommandResponse < GetAllInboundsStatsCommand . Response > > {
376- const nodeUrl = this . getNodeUrl ( url , GetAllInboundsStatsCommand . url , port ) ;
296+ ) : Promise < ICommandResponse < GetCombinedStatsCommand . Response [ 'response' ] > > {
297+ const nodeUrl = this . getNodeUrl ( url , GetCombinedStatsCommand . url , port ) ;
377298
378299 try {
379- const response = await this . axiosInstance . post < GetAllInboundsStatsCommand . Response > (
300+ const nodeResult = await this . axiosInstance . post < GetCombinedStatsCommand . Response > (
380301 nodeUrl ,
381302 data ,
382- {
383- timeout : 15_000 ,
384- } ,
385303 ) ;
386304
387305 return {
388306 isOk : true ,
389- response : response . data ,
307+ response : nodeResult . data . response ,
390308 } ;
391309 } catch ( error ) {
392310 if ( error instanceof AxiosError ) {
393- // this.logger.error(`Error in axios request: ${JSON.stringify(error.message)}`);
394-
395311 if ( error . code === '500' ) {
396312 return {
397313 isOk : false ,
@@ -418,90 +334,6 @@ export class AxiosService {
418334 }
419335 }
420336
421- public async getAllOutboundStats (
422- data : GetAllOutboundsStatsCommand . Request ,
423- url : string ,
424- port : null | number ,
425- ) : Promise < ICommandResponse < GetAllOutboundsStatsCommand . Response > > {
426- const nodeUrl = this . getNodeUrl ( url , GetAllOutboundsStatsCommand . url , port ) ;
427-
428- try {
429- const response = await this . axiosInstance . post < GetAllOutboundsStatsCommand . Response > (
430- nodeUrl ,
431- data ,
432- {
433- timeout : 15_000 ,
434- } ,
435- ) ;
436-
437- return {
438- isOk : true ,
439- response : response . data ,
440- } ;
441- } catch ( error ) {
442- if ( error instanceof AxiosError ) {
443- // this.logger.error(`Error in axios request: ${JSON.stringify(error.message)}`);
444-
445- if ( error . code === '500' ) {
446- return {
447- isOk : false ,
448- ...ERRORS . NODE_ERROR_500_WITH_MSG . withMessage (
449- JSON . stringify ( error . message ) ,
450- ) ,
451- } ;
452- }
453-
454- return {
455- isOk : false ,
456- ...ERRORS . NODE_ERROR_WITH_MSG . withMessage ( JSON . stringify ( error . message ) ) ,
457- } ;
458- } else {
459- this . logger . error ( 'Error in getAllOutboundStats:' , error ) ;
460-
461- return {
462- isOk : false ,
463- ...ERRORS . NODE_ERROR_WITH_MSG . withMessage (
464- JSON . stringify ( error ) ?? 'Unknown error' ,
465- ) ,
466- } ;
467- }
468- }
469- }
470-
471- public async getOutboundStats (
472- data : GetOutboundStatsCommand . Request ,
473- url : string ,
474- port : null | number ,
475- ) : Promise < ICommandResponse < GetOutboundStatsCommand . Response > > {
476- const nodeUrl = this . getNodeUrl ( url , GetOutboundStatsCommand . url , port ) ;
477-
478- try {
479- const response = await this . axiosInstance . post < GetOutboundStatsCommand . Response > (
480- nodeUrl ,
481- data ,
482- {
483- timeout : 15_000 ,
484- } ,
485- ) ;
486-
487- return {
488- isOk : true ,
489- response : response . data ,
490- } ;
491- } catch ( error ) {
492- if ( error instanceof AxiosError ) {
493- this . logger . error ( 'Error in getOutboundStats:' , error . response ?. data ) ;
494- } else {
495- this . logger . error ( 'Error in getOutboundStats:' , error ) ;
496- }
497-
498- return {
499- isOk : false ,
500- ...ERRORS . INTERNAL_SERVER_ERROR ,
501- } ;
502- }
503- }
504-
505337 /*
506338 * User management
507339 */
@@ -576,66 +408,4 @@ export class AxiosService {
576408 } ;
577409 }
578410 }
579-
580- public async getInboundUsers (
581- data : GetInboundUsersCommand . Request ,
582- url : string ,
583- port : null | number ,
584- ) : Promise < ICommandResponse < GetInboundUsersCommand . Response > > {
585- const nodeUrl = this . getNodeUrl ( url , GetInboundUsersCommand . url , port ) ;
586-
587- try {
588- const response = await this . axiosInstance . post < GetInboundUsersCommand . Response > (
589- nodeUrl ,
590- data ,
591- ) ;
592-
593- return {
594- isOk : true ,
595- response : response . data ,
596- } ;
597- } catch ( error ) {
598- if ( error instanceof AxiosError ) {
599- this . logger . error ( 'Error in getInboundUsers:' , error . response ?. data ) ;
600- } else {
601- this . logger . error ( 'Error in getInboundUsers:' , error ) ;
602- }
603-
604- return {
605- isOk : false ,
606- ...ERRORS . INTERNAL_SERVER_ERROR ,
607- } ;
608- }
609- }
610-
611- public async getInboundUsersCount (
612- data : GetInboundUsersCountCommand . Request ,
613- url : string ,
614- port : null | number ,
615- ) : Promise < ICommandResponse < GetInboundUsersCountCommand . Response > > {
616- const nodeUrl = this . getNodeUrl ( url , GetInboundUsersCountCommand . url , port ) ;
617-
618- try {
619- const response = await this . axiosInstance . post < GetInboundUsersCountCommand . Response > (
620- nodeUrl ,
621- data ,
622- ) ;
623-
624- return {
625- isOk : true ,
626- response : response . data ,
627- } ;
628- } catch ( error ) {
629- if ( error instanceof AxiosError ) {
630- this . logger . error ( 'Error in getInboundUsersCount:' , error . response ?. data ) ;
631- } else {
632- this . logger . error ( 'Error in getInboundUsersCount:' , error ) ;
633- }
634-
635- return {
636- isOk : false ,
637- ...ERRORS . INTERNAL_SERVER_ERROR ,
638- } ;
639- }
640- }
641411}
0 commit comments