@remnawave/xtls-sdk
Version:
A Typescript SDK for XRAY (XTLS) Core GRPC Api
43 lines (42 loc) • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetAllUsersStatsResponseModel = void 0;
/**
* Model for handling and formatting user statistics response data
*/
class GetAllUsersStatsResponseModel {
/**
* Creates an instance of GetAllUsersStatsResponseModel
* @param data Raw stats response data from the query
*/
constructor(data) {
this.users = this.parseData(data);
}
/**
* Parses and formats the raw stats data into user-specific statistics
* @param data Raw stats response data containing individual stat entries
* @returns Array of formatted user statistics
*/
parseData(data) {
const usersMap = new Map();
for (const stat of data.stat) {
const nameParts = stat.name.split('>>>');
const username = nameParts[1];
const type = nameParts[3];
const value = stat.value;
let user = usersMap.get(username);
if (!user) {
user = { username, uplink: 0, downlink: 0 };
usersMap.set(username, user);
}
if (type === 'uplink') {
user.uplink += value;
}
else if (type === 'downlink') {
user.downlink += value;
}
}
return Array.from(usersMap.values());
}
}
exports.GetAllUsersStatsResponseModel = GetAllUsersStatsResponseModel;