From b46a0b404bd9b6fddfcaeaec1e2c316015bb9967 Mon Sep 17 00:00:00 2001 From: mhsanaei Date: Thu, 18 Sep 2025 16:28:09 +0200 Subject: [PATCH] enhancements --- web/html/component/aClientTable.html | 14 ++++++------- web/html/inbounds.html | 14 ++++++++----- web/html/modals/inbound_info_modal.html | 26 +++++++++++++++++-------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/web/html/component/aClientTable.html b/web/html/component/aClientTable.html index 0626c334..0164161f 100644 --- a/web/html/component/aClientTable.html +++ b/web/html/component/aClientTable.html @@ -49,9 +49,9 @@ @@ -90,7 +90,7 @@ - + @@ -126,7 +126,7 @@ [[ remainedDays(client.expiryTime) ]] - + [[ client.reset + "d" ]] @@ -213,7 +213,7 @@ - + @@ -247,7 +247,7 @@ - + [[ client.reset + "d" ]] diff --git a/web/html/inbounds.html b/web/html/inbounds.html index 5f17c98b..bea8e8d9 100644 --- a/web/html/inbounds.html +++ b/web/html/inbounds.html @@ -1434,15 +1434,19 @@ clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null; return clientStats ? clientStats['enable'] : true; }, - // Returns true when client's traffic is exhausted or expiry time is passed isClientDepleted(dbInbound, email) { if (!email || !dbInbound || !dbInbound.clientStats) return false; const stats = dbInbound.clientStats.find(s => s.email === email); if (!stats) return false; - const now = new Date().getTime(); - const exhausted = stats.total > 0 && (stats.up + stats.down) >= stats.total; - const expired = stats.expiryTime > 0 && now >= stats.expiryTime; - return exhausted || expired; + const total = stats.total ?? 0; + const used = (stats.up ?? 0) + (stats.down ?? 0); + const hasTotal = total > 0; + const exhausted = hasTotal && used >= total; + const expiryTime = stats.expiryTime ?? 0; + const hasExpiry = expiryTime > 0; + const now = Date.now(); + const expired = hasExpiry && expiryTime <= now; + return expired || exhausted; }, isClientOnline(email) { return this.onlineClients.includes(email); diff --git a/web/html/modals/inbound_info_modal.html b/web/html/modals/inbound_info_modal.html index 55d9919c..25f43506 100644 --- a/web/html/modals/inbound_info_modal.html +++ b/web/html/modals/inbound_info_modal.html @@ -180,9 +180,9 @@ {{ i18n "status" }} - {{ i18n "enabled" }} - {{ i18n "disabled" }} {{ i18n "depleted" }} + {{ i18n "enabled" }} + {{ i18n "disabled" }} @@ -524,7 +524,7 @@ this.dbInbound = new DBInbound(dbInbound); this.clientSettings = this.inbound.clients ? this.inbound.clients[index] : null; this.isExpired = this.inbound.clients ? this.inbound.isExpiry(index) : this.dbInbound.isExpiry; - this.clientStats = this.inbound.clients ? this.dbInbound.clientStats.find(row => row.email === this.clientSettings.email) : []; + this.clientStats = this.inbound.clients ? (this.dbInbound.clientStats.find(row => row.email === this.clientSettings.email) || null) : null; if ( [ @@ -588,11 +588,21 @@ return infoModal.dbInbound.isEnable; }, get isDepleted() { - const stats = this.infoModal.clientStats; - if (!stats) return false; - const now = new Date().getTime(); - const expired = stats.expiryTime > 0 && now >= stats.expiryTime; - const exhausted = stats.total > 0 && (stats.up + stats.down) >= stats.total; + const stats = infoModal.clientStats; + const settings = infoModal.clientSettings; + if (!stats || !settings) { + return false; + } + const total = stats.total ?? 0; + const used = (stats.up ?? 0) + (stats.down ?? 0); + const hasTotal = total > 0; + const exhausted = hasTotal && used >= total; + + const expiryTime = settings.expiryTime ?? 0; + const hasExpiry = expiryTime > 0; + const now = Date.now(); + const expired = hasExpiry && now >= expiryTime; + return expired || exhausted; }, },