UNPKG

@remnawave/xtls-sdk

Version:

A Typescript SDK for XRAY (XTLS) Core GRPC Api

43 lines (42 loc) 1.47 kB
"use strict"; 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 formattedStats = data.stat.reduce((acc, curr) => { const nameParts = curr.name.split('>>>'); const username = nameParts[1]; const type = nameParts[3]; const value = curr.value; let user = acc.find((item) => item.username === username); if (!user) { user = { username, uplink: 0, downlink: 0 }; acc.push(user); } if (type === 'uplink') { user.uplink += value; } else if (type === 'downlink') { user.downlink += value; } return acc; }, []); return formattedStats; } } exports.GetAllUsersStatsResponseModel = GetAllUsersStatsResponseModel;