From b7702d0285afcdf2eed6506d68462c33d8870861 Mon Sep 17 00:00:00 2001 From: admin <362324317@qq.com> Date: Fri, 15 May 2026 06:51:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8CIP=E9=BB=98=E8=AE=A4=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E9=85=8D=E9=A2=9D=E6=94=B9=E4=B8=BA=20primaryCount=20?= =?UTF-8?q?=C3=97=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 动态计算该类型默认账号数量 primaryCount - 前 primaryCount × 2 次在同IP的两个默认账号间轮询 - 超限后再去其他非默认账号 - 无默认账号时 threshold=0, 直接走轮询 --- packages/backend/src/cloud/credential.service.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/cloud/credential.service.ts b/packages/backend/src/cloud/credential.service.ts index f079de9..c78e63b 100644 --- a/packages/backend/src/cloud/credential.service.ts +++ b/packages/backend/src/cloud/credential.service.ts @@ -456,8 +456,15 @@ export async function getAndValidateCredential(cloudType: string, ipAddress?: st const ipTodayCount = ipCountRow?.total || 0; - if (ipTodayCount < 3) { - // First 2 saves — use a primary account (is_primary=1), fallback to any healthy + // How many primary accounts does this cloud type have? + const primaryCountRow = db.prepare( + `SELECT COUNT(*) as c FROM cloud_configs WHERE cloud_type = ? AND is_primary = 1 AND is_active = 1` + ).get(cloudType) as { c: number }; + const primaryCount = primaryCountRow?.c || 0; + const primaryThreshold = primaryCount * 2; // Each primary account gets 2 uses per IP + + if (ipTodayCount < primaryThreshold) { + // First N saves (primaryCount × 2) — use primary accounts (is_primary=1), fallback to any healthy config = db.prepare( `SELECT * FROM cloud_configs WHERE cloud_type = ? AND is_active = 1 @@ -466,7 +473,7 @@ export async function getAndValidateCredential(cloudType: string, ipAddress?: st LIMIT 1` ).get(cloudType) as CloudConfig | undefined; } else { - // 3rd+ save — exclude accounts this IP has already used today, + // After primary threshold — exclude accounts this IP has already used today, // fall back to other available accounts round-robin const usedConfigIds = db.prepare( `SELECT DISTINCT config_id FROM ip_daily_save_counts