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