@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 inboundsMap = new Map();
for (const stat of data.stat) {
const nameParts = stat.name.split('>>>');
const tagValue = nameParts[1];
const type = nameParts[3];
const value = stat.value;
let inbound = inboundsMap.get(tagValue);
if (!inbound) {
inbound = { inbound: tagValue, uplink: 0, downlink: 0 };
inboundsMap.set(tagValue, inbound);
}
if (type === 'uplink') {
inbound.uplink += value;
}
else if (type === 'downlink') {
inbound.downlink += value;
}
}
return Array.from(inboundsMap.values());
}
}
exports.GetAllInboundsStatsResponseModel = GetAllInboundsStatsResponseModel;