From a34a34204c51752782a4653fa6c86a2581a6e6cc Mon Sep 17 00:00:00 2001 From: Fringg Date: Sat, 28 Mar 2026 22:32:22 +0300 Subject: [PATCH] refactor: update remnawave API types for v2.7.0 - ServerInfo: remove cpu_physical_cores, memory_available - NodeInfo: replace cpu_count/cpu_model/total_ram with versions/system, xray_uptime changed to number, users_online now required - NodeStatus: same field updates, remove dead uptime field - Extract formatUptime to shared utils/format.ts - Update AdminRemnawave and AdminDashboard components --- src/api/admin.ts | 10 +++------- src/api/adminRemnawave.ts | 37 +++++++++++++++++++++++++++++------- src/pages/AdminDashboard.tsx | 11 +++++++---- src/pages/AdminRemnawave.tsx | 28 +++++++-------------------- src/utils/format.ts | 9 +++++++++ 5 files changed, 56 insertions(+), 39 deletions(-) diff --git a/src/api/admin.ts b/src/api/admin.ts index 26bb21e..b2960ce 100644 --- a/src/api/admin.ts +++ b/src/api/admin.ts @@ -162,15 +162,11 @@ export interface NodeStatus { is_disabled: boolean; users_online: number; traffic_used_bytes?: number; - uptime?: string; - xray_version?: string; - node_version?: string; last_status_message?: string; - xray_uptime?: string; + xray_uptime: number; is_xray_running?: boolean; - cpu_count?: number; - cpu_model?: string; - total_ram?: string; + versions?: { xray: string; node: string } | null; + system?: Record | null; country_code?: string; } diff --git a/src/api/adminRemnawave.ts b/src/api/adminRemnawave.ts index 946b1d6..fb2c41a 100644 --- a/src/api/adminRemnawave.ts +++ b/src/api/adminRemnawave.ts @@ -29,11 +29,9 @@ export interface SystemSummary { export interface ServerInfo { cpu_cores: number; - cpu_physical_cores: number; memory_total: number; memory_used: number; memory_free: number; - memory_available: number; uptime_seconds: number; } @@ -78,22 +76,47 @@ export interface NodeInfo { is_disabled: boolean; is_node_online: boolean; is_xray_running: boolean; - users_online?: number; + users_online: number; traffic_used_bytes?: number; traffic_limit_bytes?: number; last_status_change?: string; last_status_message?: string; - xray_uptime?: string; + xray_uptime: number; is_traffic_tracking_active: boolean; traffic_reset_day?: number; notify_percent?: number; consumption_multiplier: number; - cpu_count?: number; - cpu_model?: string; - total_ram?: string; created_at?: string; updated_at?: string; provider_uuid?: string; + versions?: { xray: string; node: string } | null; + system?: { + info: { + arch: string; + cpus: number; + cpuModel: string; + memoryTotal: number; + hostname: string; + platform: string; + release: string; + type: string; + version: string; + networkInterfaces: string[]; + }; + stats: { + memoryFree: number; + memoryUsed: number; + uptime: number; + loadAvg: number[]; + interface?: { + interface: string; + rxBytesPerSec: number; + txBytesPerSec: number; + rxTotal: number; + txTotal: number; + } | null; + }; + } | null; active_plugin_uuid?: string; config_profile?: { active_config_profile_uuid: string | null; diff --git a/src/pages/AdminDashboard.tsx b/src/pages/AdminDashboard.tsx index a846752..685c7f8 100644 --- a/src/pages/AdminDashboard.tsx +++ b/src/pages/AdminDashboard.tsx @@ -10,6 +10,7 @@ import { type TopCampaignsResponse, type RecentPaymentsResponse, } from '../api/admin'; +import { formatUptime } from '../utils/format'; const CABINET_VERSION = __APP_VERSION__; import { useCurrency } from '../hooks/useCurrency'; @@ -254,14 +255,16 @@ function NodeCard({ node, onRestart, onToggle, isLoading }: NodeCardProps) { {/* Xray Version & Uptime */} - {(node.xray_version || node.xray_uptime) && ( + {(node.versions?.xray || node.xray_uptime > 0) && (
- {node.xray_version && ( + {node.versions?.xray && ( - Xray {node.xray_version} + Xray {node.versions.xray} )} - {node.xray_uptime && Uptime: {node.xray_uptime}} + {node.xray_uptime > 0 && ( + Uptime: {formatUptime(node.xray_uptime)} + )}
)} diff --git a/src/pages/AdminRemnawave.tsx b/src/pages/AdminRemnawave.tsx index a627d26..9e742cf 100644 --- a/src/pages/AdminRemnawave.tsx +++ b/src/pages/AdminRemnawave.tsx @@ -10,6 +10,7 @@ import { AutoSyncStatus, } from '../api/adminRemnawave'; import { usePlatform } from '../platform/hooks/usePlatform'; +import { formatUptime } from '../utils/format'; import { ServerIcon, ChartIcon, @@ -43,16 +44,6 @@ const formatBytes = (bytes: number): string => { return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }; -const formatUptime = (seconds: number): string => { - const days = Math.floor(seconds / 86400); - const hours = Math.floor((seconds % 86400) / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - - if (days > 0) return `${days}d ${hours}h`; - if (hours > 0) return `${hours}h ${minutes}m`; - return `${minutes}m`; -}; - const getCountryFlag = (code: string | null | undefined): string => { if (!code) return '🌍'; const codeMap: Record = { @@ -175,11 +166,12 @@ function NodeCard({ node, onAction, isLoading }: NodeCardProps) { {t('admin.remnawave.nodes.trafficUsed', 'used')} )} - {node.xray_uptime && ( + {node.xray_uptime > 0 && ( - {t('admin.remnawave.nodes.uptimeLabel', 'Uptime')}: {node.xray_uptime} + {t('admin.remnawave.nodes.uptimeLabel', 'Uptime')}: {formatUptime(node.xray_uptime)} )} + {node.versions?.xray && Xray {node.versions.xray}} @@ -355,15 +347,9 @@ function OverviewTab({ stats, isLoading, onRefresh }: OverviewTabProps) { ); } - // Use (total - available) instead of raw "used" to exclude disk cache/buffers - // This matches what htop/free show as actual application memory usage - const memoryActualUsed = - stats.server_info.memory_available > 0 - ? stats.server_info.memory_total - stats.server_info.memory_available - : stats.server_info.memory_used; const memoryUsedPercent = stats.server_info.memory_total > 0 - ? Math.round((memoryActualUsed / stats.server_info.memory_total) * 100) + ? Math.round((stats.server_info.memory_used / stats.server_info.memory_total) * 100) : 0; return ( @@ -437,14 +423,14 @@ function OverviewTab({ stats, isLoading, onRefresh }: OverviewTabProps) {
⚡} color="accent" /> 💾} color={memoryUsedPercent > 80 ? 'red' : memoryUsedPercent > 60 ? 'orange' : 'green'} /> diff --git a/src/utils/format.ts b/src/utils/format.ts index ca851a1..f084109 100644 --- a/src/utils/format.ts +++ b/src/utils/format.ts @@ -1,3 +1,12 @@ +export function formatUptime(seconds: number): string { + const days = Math.floor(seconds / 86400); + const hours = Math.floor((seconds % 86400) / 3600); + const minutes = Math.floor((seconds % 3600) / 60); + if (days > 0) return `${days}d ${hours}h`; + if (hours > 0) return `${hours}h ${minutes}m`; + return `${minutes}m`; +} + export function formatPrice(kopeks: number): string { const rubles = kopeks / 100; return new Intl.NumberFormat('ru-RU', {