@remnawave/xtls-sdk
Version:
A Typescript SDK for XRAY (XTLS) Core GRPC Api
43 lines (42 loc) • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetAllInboundsStatsResponseModel = void 0;
/**
* Model for handling and formatting inbound statistics response data
*/
class GetAllInboundsStatsResponseModel {
/**
* Creates an instance of GetAllInboundsStatsResponseModel
* @param data Raw stats response data from the query
*/
constructor(data) {
this.inbounds = this.parseData(data);
}
/**
* Parses and formats the raw stats data into inbound-specific statistics
* @param data Raw stats response data containing individual stat entries
* @returns Array of formatted inbound statistics
*/
parseData(data) {
const formattedStats = data.stat.reduce((acc, curr) => {
const nameParts = curr.name.split('>>>');
const tagValue = nameParts[1];
const type = nameParts[3];
const value = curr.value;
let inbound = acc.find((item) => item.inbound === tagValue);
if (!inbound) {
inbound = { inbound: tagValue, 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.GetAllInboundsStatsResponseModel = GetAllInboundsStatsResponseModel;