@remnawave/xtls-sdk
Version:
A Typescript SDK for XRAY (XTLS) Core GRPC Api
47 lines (46 loc) • 1.61 kB
JavaScript
;
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 inboundsMap = new Map();
for (const stat of data.stat) {
const nameParts = stat.name.split('>>>');
const inboundTag = nameParts[1];
const type = nameParts[3];
const value = stat.value;
let inbound = inboundsMap.get(inboundTag);
if (!inbound) {
inbound = { inbound: inboundTag, uplink: 0, downlink: 0 };
inboundsMap.set(inboundTag, inbound);
}
if (type === 'uplink') {
inbound.uplink += value;
}
else if (type === 'downlink') {
inbound.downlink += value;
}
}
return Array.from(inboundsMap.values());
}
}
exports.GetInboundStatsResponseModel = GetInboundStatsResponseModel;