UNPKG

@remnawave/xtls-sdk

Version:

A Typescript SDK for XRAY (XTLS) Core GRPC Api

43 lines (42 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetAllOutboundsStatsResponseModel = void 0; /** * Model for handling and formatting outbound statistics response data */ class GetAllOutboundsStatsResponseModel { /** * Creates an instance of GetAllOutboundsStatsResponseModel * @param data Raw stats response data from the query */ constructor(data) { this.outbounds = this.parseData(data); } /** * Parses and formats the raw stats data into outbound-specific statistics * @param data Raw stats response data containing individual stat entries * @returns Array of formatted outbound statistics */ parseData(data) { const outboundsMap = new Map(); for (const stat of data.stat) { const nameParts = stat.name.split('>>>'); const tagValue = nameParts[1]; const type = nameParts[3]; const value = stat.value; let outbound = outboundsMap.get(tagValue); if (!outbound) { outbound = { outbound: tagValue, uplink: 0, downlink: 0 }; outboundsMap.set(tagValue, outbound); } if (type === 'uplink') { outbound.uplink += value; } else if (type === 'downlink') { outbound.downlink += value; } } return Array.from(outboundsMap.values()); } } exports.GetAllOutboundsStatsResponseModel = GetAllOutboundsStatsResponseModel;