UNPKG

@localzet/xtls-sdk

Version:

TypeScript SDK for XRAY/AURA Core

47 lines (46 loc) 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetInboundStatsResponseModel = void 0; /** * Model class for handling inbound statistics response data from the Xray server. */ class GetInboundStatsResponseModel { /** * Creates a new GetInboundStatsResponseModel instance. * * @param data - The raw query stats response from the Xray server */ constructor(data) { const inbounds = this.parseData(data); this.inbound = inbounds[0] ?? null; } /** * Parses the raw stats response data into formatted inbound statistics. * * @param data - The raw query stats response to parse * @returns An array of formatted inbound statistics containing traffic data * @private */ parseData(data) { const formattedStats = data.stat.reduce((acc, curr) => { const nameParts = curr.name.split('>>>'); const inboundTag = nameParts[1]; const type = nameParts[3]; const value = curr.value; let inbound = acc.find((item) => item.inbound === inboundTag); if (!inbound) { inbound = { inbound: inboundTag, uplink: 0, downlink: 0 }; acc.push(inbound); } if (type === 'uplink') { inbound.uplink += value; } else if (type === 'downlink') { inbound.downlink += value; } return acc; }, []); return formattedStats; } } exports.GetInboundStatsResponseModel = GetInboundStatsResponseModel;