UNPKG

@remnawave/xtls-sdk

Version:

A Typescript SDK for XRAY (XTLS) Core GRPC Api

53 lines (52 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetUsersStatsResponseModel = void 0; /** * Model class for handling user statistics response data from the Xray server. */ class GetUsersStatsResponseModel { /** * Creates a new GetUserStatsResponseModel instance. * * @param data - The raw query stats response from the Xray server */ constructor(data) { const users = this.parseData(data); this.users = users; } /** * Creates a model instance from an already-parsed array of user stats, * bypassing the native `GetUsersStatsResponse` parser. * * Intended for code paths that build `UserStat[]` from other sources * (e.g. the legacy fallback that combines `GetAllOnlineUsers` and * `GetStatsOnlineIpList`). */ static fromUserStats(users) { const model = Object.create(GetUsersStatsResponseModel.prototype); model.users = users; return model; } /** * Parses the raw stats response data into formatted user statistics. * * @param data - The raw query stats response to parse * @returns An array of formatted user statistics * @private */ parseData(data) { const users = []; for (const user of data.users) { const userStat = { userId: user.email, ips: user.ips.map((ip) => ({ ip: ip.ip, lastSeen: new Date(ip.lastSeen * 1000) })), traffic: user.traffic ? { uplink: user.traffic.uplink, downlink: user.traffic.downlink } : undefined, }; users.push(userStat); } return users; } } exports.GetUsersStatsResponseModel = GetUsersStatsResponseModel;