Skip to content

Commit add1c8a

Browse files
committed
refactor: bandwidth stats endpoints
1 parent d3b8d09 commit add1c8a

File tree

60 files changed

+376
-328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+376
-328
lines changed

libs/contract/api/controllers-info.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ export const CONTROLLERS_INFO = {
2020
tag: 'Users Bulk Actions Controller',
2121
description: 'Bulk actions with users.',
2222
},
23-
USERS_STATS: {
24-
tag: 'Users Stats Controller',
25-
description: '',
26-
},
2723
HWID_USER_DEVICES: {
2824
tag: 'HWID User Devices Controller',
2925
description: '',
@@ -38,6 +34,14 @@ export const CONTROLLERS_INFO = {
3834
description:
3935
'Methods of this controller are protected with auth, most of them is returning the same informations as public Subscription Controller.',
4036
},
37+
NODES: {
38+
tag: 'Nodes Controller',
39+
description: '',
40+
},
41+
BANDWIDTH_STATS: {
42+
tag: 'Bandwidth Stats Controller',
43+
description: '',
44+
},
4145
CONFIG_PROFILES: {
4246
tag: 'Config Profiles Controller',
4347
description: 'Management of Config Profiles.',
@@ -50,10 +54,6 @@ export const CONTROLLERS_INFO = {
5054
tag: 'External Squads Controller',
5155
description: 'Management of External Squads.',
5256
},
53-
NODES: {
54-
tag: 'Nodes Controller',
55-
description: '',
56-
},
5757
HOSTS: {
5858
tag: 'Hosts Controller',
5959
description: '',
@@ -78,10 +78,6 @@ export const CONTROLLERS_INFO = {
7878
tag: 'System Controller',
7979
description: '',
8080
},
81-
BANDWIDTH_STATS: {
82-
tag: 'Bandwidth Stats Controller',
83-
description: '',
84-
},
8581
KEYGEN: {
8682
tag: 'Keygen Controller',
8783
description: 'Generation of SSL_CERT for Remnawave Node.',
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export const BANDWIDTH_STATS_CONTROLLER = 'bandwidth-stats' as const;
2+
3+
export const BANDWIDTH_STATS_NODES_ROUTE = 'nodes' as const;
4+
export const BANDWIDTH_STATS_USERS_ROUTE = 'users' as const;
5+
6+
export const BANDWIDTH_STATS_NODES_CONTROLLER =
7+
`${BANDWIDTH_STATS_CONTROLLER}/${BANDWIDTH_STATS_NODES_ROUTE}` as const;
8+
export const BANDWIDTH_STATS_USERS_CONTROLLER =
9+
`${BANDWIDTH_STATS_CONTROLLER}/${BANDWIDTH_STATS_USERS_ROUTE}` as const;
10+
11+
// Variants:
12+
// 1. Nodes -> Metrics
13+
// 2. Nodes -> Management -> Show usage (!need legacy)
14+
// 3. Users -> User -> Show Usage (!need legacy)
15+
16+
export const BANDWIDTH_STATS_ROUTES = {
17+
NODES: {
18+
// GET /bandwidth-stats/nodes –– Nodes -> Metrics
19+
GET: '',
20+
// GET /bandwidth-stats/nodes/realtime –– Nodes -> Management -> Metric Cards
21+
GET_REALTIME: 'realtime',
22+
// GET /bandwidth-stats/nodes/:nodeUuid/users –– Nodes -> Management -> Show usage
23+
GET_USERS: (uuid: string) => `${uuid}/users`,
24+
},
25+
USERS: {
26+
// GET /bandwidth-stats/users/:userUuid –– Users -> User -> Show Usage
27+
GET_BY_UUID: (uuid: string) => `${uuid}`,
28+
},
29+
LEGACY: {
30+
NODES: {
31+
// GET /bandwidth-stats/nodes/:nodeUuid/users/legacy –– Nodes -> Management -> Show usage (legacy)
32+
GET_USERS: (uuid: string) => `${uuid}/users/legacy`,
33+
},
34+
USERS: {
35+
// GET /bandwidth-stats/users/:userUuid/legacy –– Users -> User -> Show Usage (legacy)
36+
GET_BY_UUID: (uuid: string) => `${uuid}/legacy`,
37+
},
38+
},
39+
} as const;

libs/contract/api/controllers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './api-tokens';
22
export * from './auth';
3+
export * from './bandwidth-stats';
34
export * from './config-profiles';
45
export * from './external-squads';
56
export * from './hosts';

libs/contract/api/controllers/nodes.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ export const NODES_ROUTES = {
2323
PROFILE_MODIFICATION: `${BULK_ACTIONS_ROUTE}/profile-modification`,
2424
},
2525

26-
STATS: {
27-
USAGE_BY_RANGE: 'usage/range',
28-
USAGE_BY_RANGE_USER: (uuid: string) => `usage/${uuid}/users/range`,
29-
USAGE_REALTIME: 'usage/realtime',
30-
},
31-
3226
TAGS: {
3327
GET: 'tags',
3428
},

libs/contract/api/controllers/users.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ export const USERS_ROUTES = {
4141
},
4242
},
4343

44-
STATS: {
45-
GET_USAGE_BY_RANGE: (uuid: string) => `stats/usage/${uuid}/range`,
46-
},
47-
4844
TAGS: {
4945
GET: 'tags',
5046
},

libs/contract/api/routes.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ export const REST_API = {
7575
BULK_ACTIONS: {
7676
PROFILE_MODIFICATION: `${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.BULK_ACTIONS.PROFILE_MODIFICATION}`,
7777
},
78-
79-
STATS: {
80-
USAGE_BY_RANGE: `${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.STATS.USAGE_BY_RANGE}`,
81-
USAGE_BY_RANGE_USER: (uuid: string) =>
82-
`${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.STATS.USAGE_BY_RANGE_USER(
83-
uuid,
84-
)}`,
85-
USAGE_REALTIME: `${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.STATS.USAGE_REALTIME}`,
86-
},
8778
},
8879
USERS: {
8980
CREATE: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.CREATE}`,
@@ -163,13 +154,6 @@ export const REST_API = {
163154
EXTEND_EXPIRATION_DATE: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.BULK.ALL.EXTEND_EXPIRATION_DATE}`,
164155
},
165156
},
166-
STATS: {
167-
GET_USAGE_BY_RANGE: (uuid: string) =>
168-
`${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.STATS.GET_USAGE_BY_RANGE(
169-
uuid,
170-
)}`,
171-
},
172-
173157
TAGS: {
174158
GET: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.TAGS.GET}`,
175159
},
@@ -334,7 +318,6 @@ export const REST_API = {
334318
REORDER: `${ROOT}/${CONTROLLERS.INTERNAL_SQUADS_CONTROLLER}/${CONTROLLERS.INTERNAL_SQUADS_ROUTES.ACTIONS.REORDER}`,
335319
},
336320
},
337-
338321
INFRA_BILLING: {
339322
GET_PROVIDERS: `${ROOT}/${CONTROLLERS.INFRA_BILLING_CONTROLLER}/${CONTROLLERS.INFRA_BILLING_ROUTES.GET_PROVIDERS}`,
340323
CREATE_PROVIDER: `${ROOT}/${CONTROLLERS.INFRA_BILLING_CONTROLLER}/${CONTROLLERS.INFRA_BILLING_ROUTES.CREATE_PROVIDER}`,
@@ -404,4 +387,26 @@ export const REST_API = {
404387
CLONE: `${ROOT}/${CONTROLLERS.SUBSCRIPTION_PAGE_CONFIGS_CONTROLLER}/${CONTROLLERS.SUBSCRIPTION_PAGE_CONFIGS_ROUTES.ACTIONS.CLONE}`,
405388
},
406389
},
390+
BANDWIDTH_STATS: {
391+
NODES: {
392+
GET: `${ROOT}/${CONTROLLERS.BANDWIDTH_STATS_CONTROLLER}/${CONTROLLERS.BANDWIDTH_STATS_NODES_ROUTE}/${CONTROLLERS.BANDWIDTH_STATS_ROUTES.NODES.GET}`,
393+
GET_REALTIME: `${ROOT}/${CONTROLLERS.BANDWIDTH_STATS_CONTROLLER}/${CONTROLLERS.BANDWIDTH_STATS_NODES_ROUTE}/${CONTROLLERS.BANDWIDTH_STATS_ROUTES.NODES.GET_REALTIME}`,
394+
GET_USERS: (uuid: string) =>
395+
`${ROOT}/${CONTROLLERS.BANDWIDTH_STATS_CONTROLLER}/${CONTROLLERS.BANDWIDTH_STATS_NODES_ROUTE}/${CONTROLLERS.BANDWIDTH_STATS_ROUTES.NODES.GET_USERS(uuid)}`,
396+
},
397+
USERS: {
398+
GET_BY_UUID: (uuid: string) =>
399+
`${ROOT}/${CONTROLLERS.BANDWIDTH_STATS_CONTROLLER}/${CONTROLLERS.BANDWIDTH_STATS_USERS_ROUTE}/${CONTROLLERS.BANDWIDTH_STATS_ROUTES.USERS.GET_BY_UUID(uuid)}`,
400+
},
401+
LEGACY: {
402+
NODES: {
403+
GET_USERS: (uuid: string) =>
404+
`${ROOT}/${CONTROLLERS.BANDWIDTH_STATS_CONTROLLER}/${CONTROLLERS.BANDWIDTH_STATS_NODES_ROUTE}/${CONTROLLERS.BANDWIDTH_STATS_ROUTES.LEGACY.NODES.GET_USERS(uuid)}`,
405+
},
406+
USERS: {
407+
GET_BY_UUID: (uuid: string) =>
408+
`${ROOT}/${CONTROLLERS.BANDWIDTH_STATS_CONTROLLER}/${CONTROLLERS.BANDWIDTH_STATS_USERS_ROUTE}/${CONTROLLERS.BANDWIDTH_STATS_ROUTES.LEGACY.USERS.GET_BY_UUID(uuid)}`,
409+
},
410+
},
411+
},
407412
} as const;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './legacy';
2+
export * from './nodes';
3+
export * from './users';

libs/contract/commands/nodes/stats/get-node-user-usage-by-range.command.ts renamed to libs/contract/commands/bandwidth-stats/legacy/get-legacy-stats-node-user-usage.command.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { z } from 'zod';
22

3+
import { BANDWIDTH_STATS_ROUTES, REST_API } from '../../../api';
34
import { getEndpointDetails } from '../../../constants';
4-
import { NODES_ROUTES, REST_API } from '../../../api';
55

6-
export namespace GetNodeUserUsageByRangeCommand {
7-
export const url = REST_API.NODES.STATS.USAGE_BY_RANGE_USER;
6+
export namespace GetLegacyStatsNodeUserUsageCommand {
7+
export const url = REST_API.BANDWIDTH_STATS.LEGACY.NODES.GET_USERS;
88
export const TSQ_url = url(':uuid');
99

1010
export const endpointDetails = getEndpointDetails(
11-
NODES_ROUTES.STATS.USAGE_BY_RANGE_USER(':uuid'),
11+
BANDWIDTH_STATS_ROUTES.LEGACY.NODES.GET_USERS(':uuid'),
1212
'get',
13-
'Get node user usage by range and Node UUID',
13+
'Get Node User Usage by Range and Node UUID (Legacy)',
1414
);
1515

1616
export const RequestSchema = z.object({

libs/contract/commands/users/get-user-usage-by-range.command.ts renamed to libs/contract/commands/bandwidth-stats/legacy/get-legacy-user-usage.command.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { z } from 'zod';
22

3-
import { getEndpointDetails } from '../../constants';
4-
import { REST_API, USERS_ROUTES } from '../../api';
3+
import { BANDWIDTH_STATS_ROUTES, REST_API } from '../../../api';
4+
import { getEndpointDetails } from '../../../constants';
55

6-
export namespace GetUserUsageByRangeCommand {
7-
export const url = REST_API.USERS.STATS.GET_USAGE_BY_RANGE;
6+
export namespace GetLegacyStatsUserUsageCommand {
7+
export const url = REST_API.BANDWIDTH_STATS.LEGACY.USERS.GET_BY_UUID;
88
export const TSQ_url = url(':uuid');
99

1010
export const endpointDetails = getEndpointDetails(
11-
USERS_ROUTES.STATS.GET_USAGE_BY_RANGE(':uuid'),
11+
BANDWIDTH_STATS_ROUTES.LEGACY.USERS.GET_BY_UUID(':uuid'),
1212
'get',
13-
'Get user usage by range',
13+
'Get User Usage by Range (Legacy)',
1414
);
1515

1616
export const RequestSchema = z.object({
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './get-legacy-stats-node-user-usage.command';
2+
export * from './get-legacy-user-usage.command';

0 commit comments

Comments
 (0)