MCPcopy Index your code
hub / github.com/QLHazyCoder/FlowPilot / resolveVerificationStep

Function resolveVerificationStep

background/verification-flow.js:368–487  ·  view source on GitHub ↗
(step, state, mail, options = {})

Source from the content-addressed store, hash-verified

366 }
367
368 async function resolveVerificationStep(step, state, mail, options = {}) {
369 const stateKey = getVerificationCodeStateKey(step);
370 const rejectedCodes = new Set();
371 const hotmailPollConfig = mail.provider === HOTMAIL_PROVIDER
372 ? getHotmailVerificationPollConfig(step)
373 : null;
374 const beforeSubmit = typeof options.beforeSubmit === 'function'
375 ? options.beforeSubmit
376 : null;
377 const ignorePersistedLastCode = Boolean(hotmailPollConfig?.ignorePersistedLastCode);
378 if (state[stateKey] && !ignorePersistedLastCode) {
379 rejectedCodes.add(state[stateKey]);
380 }
381
382 let nextFilterAfterTimestamp = options.filterAfterTimestamp ?? null;
383 const requestFreshCodeFirst = options.requestFreshCodeFirst !== undefined
384 ? Boolean(options.requestFreshCodeFirst)
385 : (hotmailPollConfig?.requestFreshCodeFirst ?? false);
386 const maxSubmitAttempts = 3;
387 const resendIntervalMs = Math.max(0, Number(options.resendIntervalMs) || 0);
388 let lastResendAt = Number(options.lastResendAt) || 0;
389
390 const updateFilterAfterTimestampForStep7 = async (requestedAt) => {
391 if (step !== 7 || !requestedAt) {
392 return nextFilterAfterTimestamp;
393 }
394
395 if (mail.provider === HOTMAIL_PROVIDER) {
396 nextFilterAfterTimestamp = getHotmailVerificationRequestTimestamp(7, {
397 ...state,
398 loginVerificationRequestedAt: requestedAt,
399 });
400 } else {
401 nextFilterAfterTimestamp = Math.max(0, Number(requestedAt) - 60000);
402 }
403
404 return nextFilterAfterTimestamp;
405 };
406
407 if (requestFreshCodeFirst) {
408 try {
409 lastResendAt = await requestVerificationCodeResend(step);
410 await updateFilterAfterTimestampForStep7(lastResendAt);
411 await addLog(`步骤 ${step}:已先请求一封新的${getVerificationCodeLabel(step)}验证码,再开始轮询邮箱。`, 'warn');
412 } catch (err) {
413 if (isStopError(err)) {
414 throw err;
415 }
416 await addLog(`步骤 ${step}:首次重新获取验证码失败:${err.message},将继续使用当前时间窗口轮询。`, 'warn');
417 }
418 }
419
420 if (mail.provider === HOTMAIL_PROVIDER) {
421 const initialDelayMs = Number(options.initialDelayMs ?? hotmailPollConfig.initialDelayMs) || 0;
422 if (initialDelayMs > 0) {
423 await addLog(`步骤 ${step}:等待 ${Math.round(initialDelayMs / 1000)} 秒,让 Hotmail 验证码邮件先到达...`, 'info');
424 await sleepWithStop(initialDelayMs);
425 }

Callers 2

executeStep4Function · 0.50
runStep7AttemptFunction · 0.50

Calls 13

sleepWithStopFunction · 0.85
setStateFunction · 0.85
addLogFunction · 0.70
getVerificationCodeLabelFunction · 0.70
submitVerificationCodeFunction · 0.70
isStopErrorFunction · 0.50

Tested by

no test coverage detected