Skip to content

Commit 3d70d29

Browse files
committed
chore: update @remnawave/node-contract to version 0.6.0 and refactor axios service to consolidate stats retrieval
1 parent 1a45c29 commit 3d70d29

File tree

10 files changed

+62
-315
lines changed

10 files changed

+62
-315
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"@prisma/adapter-pg": "6.19.0",
7878
"@prisma/client": "6.19.0",
7979
"@remnawave/hashed-set": "^0.0.4",
80-
"@remnawave/node-contract": "0.5.9",
80+
"@remnawave/node-contract": "0.6.0",
8181
"@remnawave/xtls-sdk": "^0.7.0",
8282
"@scalar/nestjs-api-reference": "^1.0.8",
8383
"@simplewebauthn/server": "^13.2.2",

src/common/axios/axios.service.ts

Lines changed: 7 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,13 @@ import { CommandBus } from '@nestjs/cqrs';
88

99
import {
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

2820
import { 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
}

src/modules/nodes/events/add-user-to-node/add-user-to-node.handler.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,26 @@ export class AddUserToNodeHandler implements IEventHandler<AddUserToNodeEvent> {
5959
type: inboundType,
6060
username: tId.toString(),
6161
password: trojanPassword,
62-
level: 0,
6362
tag: inbound.tag,
63+
level: 0,
6464
};
6565
case 'vless':
6666
return {
6767
type: inboundType,
6868
username: tId.toString(),
6969
uuid: vlessUuid,
7070
flow: getVlessFlowFromDbInbound(inbound),
71-
level: 0,
7271
tag: inbound.tag,
7372
};
7473
case 'shadowsocks':
7574
return {
7675
type: inboundType,
7776
username: tId.toString(),
7877
password: ssPassword,
79-
level: 0,
8078
tag: inbound.tag,
8179
cipherType: CipherType.CHACHA20_POLY1305,
8280
ivCheck: false,
81+
level: 0,
8382
};
8483
default:
8584
throw new Error(`Unsupported inbound type: ${inboundType}`);

src/modules/users/queries/get-prepared-config-with-users/get-prepared-config-with-users.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class GetPreparedConfigWithUsersHandler implements IQueryHandler<
9090
isOk: true,
9191
response: {
9292
config: config.getConfig(),
93-
hashes: {
93+
hashesPayload: {
9494
emptyConfig: configHash,
9595
inbounds: Array.from(inboundsUserSets.entries()).map(([tag, set]) => ({
9696
usersCount: set.size,

0 commit comments

Comments
 (0)