UNPKG

@localzet/xtls-sdk

Version:

TypeScript SDK for XRAY/AURA Core

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 formattedStats = data.stat.reduce((acc, curr) => { const nameParts = curr.name.split('>>>'); const outboundTag = nameParts[1]; const type = nameParts[3]; const value = curr.value; let outbound = acc.find((item) => item.outbound === outboundTag); if (!outbound) { outbound = { outbound: outboundTag, uplink: 0, downlink: 0 }; acc.push(outbound); } if (type === 'uplink') { outbound.uplink += value; } else if (type === 'downlink') { outbound.downlink += value; } return acc; }, []); return formattedStats; } } exports.GetOutboundStatsResponseModel = GetOutboundStatsResponseModel;