D58·代码审查反馈修复·池配额缓存优化+百分比边界处理+注释改进

Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/e78a092d-e987-459c-96bd-e99135555b3c

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-05 12:06:55 +00:00 committed by GitHub
parent 8cb9374fa3
commit 2e5ca40f12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 5 deletions

View File

@ -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 · 多节点) ─────

View File

@ -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`);

View File

@ -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: {