From 2e5ca40f12087ea39347e696bcf4f22120efd019 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:06:55 +0000 Subject: [PATCH] =?UTF-8?q?D58=C2=B7=E4=BB=A3=E7=A0=81=E5=AE=A1=E6=9F=A5?= =?UTF-8?q?=E5=8F=8D=E9=A6=88=E4=BF=AE=E5=A4=8D=C2=B7=E6=B1=A0=E9=85=8D?= =?UTF-8?q?=E9=A2=9D=E7=BC=93=E5=AD=98=E4=BC=98=E5=8C=96+=E7=99=BE?= =?UTF-8?q?=E5=88=86=E6=AF=94=E8=BE=B9=E7=95=8C=E5=A4=84=E7=90=86+?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/e78a092d-e987-459c-96bd-e99135555b3c Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> --- server/proxy/service/subscription-server-v2.js | 18 +++++++++++++++--- server/proxy/service/traffic-monitor-v2.js | 2 +- server/proxy/service/user-manager.js | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/server/proxy/service/subscription-server-v2.js b/server/proxy/service/subscription-server-v2.js index 28c04564..8d1eb5fe 100644 --- a/server/proxy/service/subscription-server-v2.js +++ b/server/proxy/service/subscription-server-v2.js @@ -152,16 +152,28 @@ function buildStaticNodes() { // ── 生成subscription-userinfo头 ────────────── // 共享流量池模型: total=池配额(2000GB),upload+download=池总用量 +// 使用缓存的池状态文件(traffic-monitor-v2每5分钟更新)以减少计算开销 function generateUserInfoHeader(user) { const nextMonth = new Date(); nextMonth.setMonth(nextMonth.getMonth() + 1); nextMonth.setDate(1); nextMonth.setHours(0, 0, 0, 0); - // 获取流量池总用量 (所有用户汇总) - const poolStatus = userManager.getPoolStatus(); + // 优先从缓存文件读取池状态 (traffic-monitor-v2每5分钟写入) + let poolUpload = 0; + let poolDownload = 0; + try { + const cached = JSON.parse(fs.readFileSync(path.join(DATA_DIR, 'pool-quota-status.json'), 'utf8')); + poolUpload = cached.pool_upload_bytes || 0; + poolDownload = cached.pool_download_bytes || 0; + } catch { + // 缓存不可用时实时计算 + const poolStatus = userManager.getPoolStatus(); + poolUpload = poolStatus.pool_upload_bytes; + poolDownload = poolStatus.pool_download_bytes; + } - return `upload=${poolStatus.pool_upload_bytes}; download=${poolStatus.pool_download_bytes}; total=${userManager.POOL_QUOTA_BYTES}; expire=${Math.floor(nextMonth.getTime() / 1000)}`; + return `upload=${poolUpload}; download=${poolDownload}; total=${userManager.POOL_QUOTA_BYTES}; expire=${Math.floor(nextMonth.getTime() / 1000)}`; } // ── 生成VLESS URI (Shadowrocket · 多节点) ───── diff --git a/server/proxy/service/traffic-monitor-v2.js b/server/proxy/service/traffic-monitor-v2.js index 2a739497..cbb6f5d9 100644 --- a/server/proxy/service/traffic-monitor-v2.js +++ b/server/proxy/service/traffic-monitor-v2.js @@ -101,7 +101,7 @@ function checkPoolAlerts(poolStatus) { alertState.alerts_sent = { p80: false, p90: false, p100: false }; } - const pct = poolStatus.pool_percentage; + const pct = Math.min(poolStatus.pool_percentage, 100); if (pct >= 100 && !alertState.alerts_sent.p100) { console.log(`[V2流量监控] ⚠️ 流量池已用完! ${poolStatus.pool_used_gb.toFixed(2)}GB / ${poolStatus.pool_total_gb}GB`); diff --git a/server/proxy/service/user-manager.js b/server/proxy/service/user-manager.js index 6ab49f96..a98ab936 100644 --- a/server/proxy/service/user-manager.js +++ b/server/proxy/service/user-manager.js @@ -137,7 +137,7 @@ function addUser(email, options = {}) { uuid: generateUUID(), token: generateToken(), label: options.label || email.split('@')[0], - quota_bytes: POOL_QUOTA_BYTES, // 共享流量池配额(展示用·实际按池总量控制) + quota_bytes: POOL_QUOTA_BYTES, // 存储池配额引用·实际配额由池级别统一控制(getPoolStatus)·非独立限额 enabled: true, created_at: now.toISOString(), traffic: {