From 76c104e99eb088a483c7cc62bbaf145b6260ca58 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 04:29:58 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E6=AF=94=E8=BE=83=E9=80=BB=E8=BE=91=20+=20SMTP=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=B8=85=E7=90=86=20+=20=E5=AE=89=E5=85=A8=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/c5b8b0a2-c3fb-437f-bd6f-07549f2c5709 Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> --- .github/workflows/infinity-evolution.yml | 13 +++++---- server/proxy/service/auto-evolution.js | 26 +++++++++--------- server/proxy/service/email-hub.js | 34 ++++++++++++++++++------ 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/.github/workflows/infinity-evolution.yml b/.github/workflows/infinity-evolution.yml index db2fed5b..dad4d7f3 100644 --- a/.github/workflows/infinity-evolution.yml +++ b/.github/workflows/infinity-evolution.yml @@ -81,18 +81,21 @@ jobs: deploy-infinity) echo "部署∞版本..." # 先同步最新代码到服务器 + $SSH_CMD "mkdir -p $PROXY_DIR/.deploy-tmp" + scp -i ~/.ssh/brain_key -o StrictHostKeyChecking=no \ server/proxy/service/auto-evolution.js \ server/proxy/service/email-hub.js \ server/proxy/service/protocol-mirror.js \ server/proxy/ecosystem.brain-proxy-v3.config.js \ - ${{ secrets.ZY_BRAIN_USER }}@${{ secrets.ZY_BRAIN_HOST }}:/tmp/ + ${{ secrets.ZY_BRAIN_USER }}@${{ secrets.ZY_BRAIN_HOST }}:$PROXY_DIR/.deploy-tmp/ $SSH_CMD " - cp /tmp/auto-evolution.js $PROXY_DIR/service/ - cp /tmp/email-hub.js $PROXY_DIR/service/ - cp /tmp/protocol-mirror.js $PROXY_DIR/service/ - cp /tmp/ecosystem.brain-proxy-v3.config.js $PROXY_DIR/ + cp $PROXY_DIR/.deploy-tmp/auto-evolution.js $PROXY_DIR/service/ + cp $PROXY_DIR/.deploy-tmp/email-hub.js $PROXY_DIR/service/ + cp $PROXY_DIR/.deploy-tmp/protocol-mirror.js $PROXY_DIR/service/ + cp $PROXY_DIR/.deploy-tmp/ecosystem.brain-proxy-v3.config.js $PROXY_DIR/ + rm -rf $PROXY_DIR/.deploy-tmp mkdir -p $PROXY_DIR/data/evolution-reports cd $PROXY_DIR && pm2 startOrRestart ecosystem.brain-proxy-v3.config.js --update-env && pm2 save echo '✅ ∞版本已部署' diff --git a/server/proxy/service/auto-evolution.js b/server/proxy/service/auto-evolution.js index 4c459ab6..95b50445 100644 --- a/server/proxy/service/auto-evolution.js +++ b/server/proxy/service/auto-evolution.js @@ -372,8 +372,9 @@ async function checkTrafficPoolAlert() { const lastRun = status.schedules.traffic_alert_70.last_run; const currentPeriod = pool.period || new Date().toISOString().slice(0, 7); - // 检查本月是否已发过 - if (!lastRun || !lastRun.startsWith(currentPeriod.replace('-', '').slice(0, 6))) { + // 检查本月是否已发过 (比较YYYY-MM) + const lastRunMonth = lastRun ? lastRun.slice(0, 7) : ''; + if (lastRunMonth !== currentPeriod) { await handleTrafficAlert(Math.round(pct)); status.schedules.traffic_alert_70.last_run = new Date().toISOString(); saveEvolutionStatus(status); @@ -408,19 +409,16 @@ async function checkSchedule() { // ── 月度进化 (每月1号 00:00-00:04) ── if (day === 1 && hour === 0 && minute < 5) { const lastMonthly = status.schedules.monthly_evolution.last_run; - const today = now.toISOString().slice(0, 10); - if (!lastMonthly || !lastMonthly.startsWith(today.slice(0, 4))) { - // 进一步检查: 确保本月还没执行过 - const lastRunDate = lastMonthly ? new Date(lastMonthly) : null; - const lastRunMonth = lastRunDate ? `${lastRunDate.getFullYear()}-${String(lastRunDate.getMonth() + 1).padStart(2, '0')}` : ''; - const currentMonth = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`; + // 比较YYYY-MM确保本月未执行过 + const lastRunDate = lastMonthly ? new Date(lastMonthly) : null; + const lastRunMonth = lastRunDate ? `${lastRunDate.getFullYear()}-${String(lastRunDate.getMonth() + 1).padStart(2, '0')}` : ''; + const currentMonth = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`; - if (lastRunMonth !== currentMonth) { - try { - await monthlyEvolution(); - } catch (err) { - console.error('[自主进化] 月度进化调度异常:', err.message); - } + if (lastRunMonth !== currentMonth) { + try { + await monthlyEvolution(); + } catch (err) { + console.error('[自主进化] 月度进化调度异常:', err.message); } } } diff --git a/server/proxy/service/email-hub.js b/server/proxy/service/email-hub.js index efadd877..b53329aa 100644 --- a/server/proxy/service/email-hub.js +++ b/server/proxy/service/email-hub.js @@ -86,6 +86,15 @@ async function sendEmail(to, subject, htmlBody) { const smtpPort = 465; return new Promise((resolve, reject) => { + let settled = false; + const timeoutId = setTimeout(() => { + if (!settled) { + settled = true; + try { socket.destroy(); } catch { /* ignore */ } + reject(new Error('SMTP超时(30s)')); + } + }, 30000); + const socket = tls.connect(smtpPort, smtpHost, {}, () => { let step = 0; const from = config.smtp_user; @@ -107,20 +116,29 @@ async function sendEmail(to, subject, htmlBody) { socket.write(commands[step]); step++; } - if (step >= commands.length) { + if (step >= commands.length && !settled) { + settled = true; + clearTimeout(timeoutId); resolve(true); } }); - socket.on('error', (err) => { reject(err); }); + socket.on('error', (err) => { + if (!settled) { + settled = true; + clearTimeout(timeoutId); + reject(err); + } + }); }); - socket.on('error', (err) => { reject(err); }); - - setTimeout(() => { - try { socket.destroy(); } catch { /* ignore */ } - reject(new Error('SMTP超时(30s)')); - }, 30000); + socket.on('error', (err) => { + if (!settled) { + settled = true; + clearTimeout(timeoutId); + reject(err); + } + }); }); }