UNPKG

@remnawave/xtls-sdk

Version:

A Typescript SDK for XRAY (XTLS) Core GRPC Api

47 lines (46 loc) 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetOutboundStatsResponseModel = void 0; /** * Model class for handling outbound statistics response data from the Xray server. */ class GetOutboundStatsResponseModel { /** * Creates a new GetOutboundStatsResponseModel instance. * * @param data - The raw query stats response from the Xray server */ constructor(data) { const outbounds = this.parseData(data); this.outbound = outbounds[0] ?? null; } /** * Parses the raw stats response data into formatted outbound statistics. * * @param data - The raw query stats response to parse * @returns An array of formatted outbound statistics containing traffic data * @private */ parseData(data) { const outboundsMap = new Map(); for (const stat of data.stat) { const nameParts = stat.name.split('>>>'); const outboundTag = nameParts[1]; const type = nameParts[3]; const value = stat.value; let outbound = outboundsMap.get(outboundTag); if (!outbound) { outbound = { outbound: outboundTag, uplink: 0, downlink: 0 }; outboundsMap.set(outboundTag, outbound); } if (type === 'uplink') { outbound.uplink += value; } else if (type === 'downlink') { outbound.downlink += value; } } return Array.from(outboundsMap.values()); } } exports.GetOutboundStatsResponseModel = GetOutboundStatsResponseModel;