Bladeren bron

feat: 在验证码请求流程中添加首次请求新验证码的选项,优化邮箱轮询逻辑

QLHazyCoder 4 maanden geleden
bovenliggende
commit
ed97ec4a4a
1 gewijzigde bestanden met toevoegingen van 18 en 2 verwijderingen
  1. 18 2
      background.js

+ 18 - 2
background.js

@@ -1759,8 +1759,18 @@ async function resolveVerificationStep(step, state, mail, options = {}) {
   }
 
   let nextFilterAfterTimestamp = options.filterAfterTimestamp ?? null;
+  const requestFreshCodeFirst = Boolean(options.requestFreshCodeFirst);
   const maxSubmitAttempts = 3;
 
+  if (requestFreshCodeFirst) {
+    try {
+      nextFilterAfterTimestamp = await requestVerificationCodeResend(step);
+      await addLog(`步骤 ${step}:已先请求一封新的${getVerificationCodeLabel(step)}验证码,再开始轮询邮箱。`, 'warn');
+    } catch (err) {
+      await addLog(`步骤 ${step}:首次重新获取验证码失败:${err.message},将继续使用当前时间窗口轮询。`, 'warn');
+    }
+  }
+
   for (let attempt = 1; attempt <= maxSubmitAttempts; attempt++) {
     const result = await pollFreshVerificationCode(step, state, mail, {
       excludeCodes: [...rejectedCodes],
@@ -1851,7 +1861,10 @@ async function executeStep4(state) {
     });
   }
 
-  await resolveVerificationStep(4, state, mail, { filterAfterTimestamp: stepStartedAt });
+  await resolveVerificationStep(4, state, mail, {
+    filterAfterTimestamp: stepStartedAt,
+    requestFreshCodeFirst: true,
+  });
   return;
 }
 
@@ -1966,7 +1979,10 @@ async function executeStep7(state) {
     });
   }
 
-  await resolveVerificationStep(7, state, mail, { filterAfterTimestamp: stepStartedAt });
+  await resolveVerificationStep(7, state, mail, {
+    filterAfterTimestamp: stepStartedAt,
+    requestFreshCodeFirst: true,
+  });
   return;
 }