第七步添加检测重试页面会跳第六步的逻辑

This commit is contained in:
QLHazyCoder
2026-04-14 16:47:08 +08:00
parent 89854f17f2
commit a4aee4dd61
2 changed files with 69 additions and 38 deletions
+22 -21
View File
@@ -28,7 +28,7 @@ const HOTMAIL_MAILBOXES = ['INBOX', 'Junk'];
const STOP_ERROR_MESSAGE = '流程已被用户停止。'; const STOP_ERROR_MESSAGE = '流程已被用户停止。';
const HUMAN_STEP_DELAY_MIN = 700; const HUMAN_STEP_DELAY_MIN = 700;
const HUMAN_STEP_DELAY_MAX = 2200; const HUMAN_STEP_DELAY_MAX = 2200;
const STEP7_RESTART_MAX_ROUNDS = 8; const STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS = 8;
const SUB2API_STEP1_RESPONSE_TIMEOUT_MS = 90000; const SUB2API_STEP1_RESPONSE_TIMEOUT_MS = 90000;
const SUB2API_STEP9_RESPONSE_TIMEOUT_MS = 120000; const SUB2API_STEP9_RESPONSE_TIMEOUT_MS = 120000;
const DEFAULT_SUB2API_URL = 'https://sub2api.hisence.fun/admin/accounts'; const DEFAULT_SUB2API_URL = 'https://sub2api.hisence.fun/admin/accounts';
@@ -2208,10 +2208,6 @@ function isStep7RestartFromStep6Error(error) {
|| Boolean(parseStep7RestartFromStep6Marker(error)); || Boolean(parseStep7RestartFromStep6Marker(error));
} }
function isStep7RecoverableError(error) {
return isVerificationMailPollingError(error) || isStep7RestartFromStep6Error(error);
}
function isRestartCurrentAttemptError(error) { function isRestartCurrentAttemptError(error) {
const message = String(typeof error === 'string' ? error : error?.message || ''); const message = String(typeof error === 'string' ? error : error?.message || '');
return /当前邮箱已存在,需要重新开始新一轮/.test(message); return /当前邮箱已存在,需要重新开始新一轮/.test(message);
@@ -5227,43 +5223,48 @@ async function rerunStep6ForStep7Recovery() {
} }
async function executeStep7(state) { async function executeStep7(state) {
let lastError = null; let currentState = state;
let mailPollingAttempt = 1;
for (let round = 1; round <= STEP7_RESTART_MAX_ROUNDS; round++) { let lastMailPollingError = null;
const currentState = round === 1 ? state : await getState();
while (true) {
try { try {
if (round > 1) {
await addLog(`步骤 7:正在进行第 ${round}/${STEP7_RESTART_MAX_ROUNDS} 轮登录验证码恢复尝试。`, 'warn');
}
await runStep7Attempt(currentState); await runStep7Attempt(currentState);
return; return;
} catch (err) { } catch (err) {
lastError = err; if (isStep7RestartFromStep6Error(err)) {
await addLog('步骤 7:检测到登录页超时报错,准备从步骤 6 重新开始...', 'warn');
await rerunStep6ForStep7Recovery();
currentState = await getState();
continue;
}
if (!isStep7RecoverableError(err)) { if (!isVerificationMailPollingError(err)) {
throw err; throw err;
} }
if (round >= STEP7_RESTART_MAX_ROUNDS) { lastMailPollingError = err;
if (mailPollingAttempt >= STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS) {
break; break;
} }
mailPollingAttempt += 1;
await addLog( await addLog(
isStep7RestartFromStep6Error(err) `步骤 7:检测到邮箱轮询类失败,准备从步骤 6 重新开始(${mailPollingAttempt}/${STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS}...`,
? `步骤 7:检测到登录页超时报错,准备从步骤 6 重新开始(${round + 1}/${STEP7_RESTART_MAX_ROUNDS}...`
: `步骤 7:检测到邮箱轮询类失败,准备从步骤 6 重新开始(${round + 1}/${STEP7_RESTART_MAX_ROUNDS}...`,
'warn' 'warn'
); );
await rerunStep6ForStep7Recovery(); await rerunStep6ForStep7Recovery();
currentState = await getState();
} }
} }
if (lastError && isStep7RecoverableError(lastError)) { if (lastMailPollingError) {
throw new Error(`步骤 7:登录验证码流程在 ${STEP7_RESTART_MAX_ROUNDS} 轮恢复后仍未成功。最后一次原因:${lastError.message}`); throw new Error(
`步骤 7:登录验证码流程在 ${STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS} 轮邮箱轮询恢复后仍未成功。最后一次原因:${lastMailPollingError.message}`
);
} }
throw lastError || new Error(`步骤 7:登录验证码流程${STEP7_RESTART_MAX_ROUNDS} 轮后仍未成功。`); throw new Error('步骤 7:登录验证码流程未成功完成。');
} }
// ============================================================ // ============================================================
+47 -17
View File
@@ -529,10 +529,6 @@ function isAddPhonePageReady() {
return ADD_PHONE_PAGE_PATTERN.test(getPageTextSnapshot()); return ADD_PHONE_PAGE_PATTERN.test(getPageTextSnapshot());
} }
function isLoginPage() {
return /\/log-in(?:[/?#]|$)/i.test(location.pathname || '');
}
function isStep8Ready() { function isStep8Ready() {
const continueBtn = getPrimaryContinueButton(); const continueBtn = getPrimaryContinueButton();
if (!continueBtn) return false; if (!continueBtn) return false;
@@ -691,19 +687,51 @@ function getAuthRetryButton({ allowDisabled = false } = {}) {
}) || null; }) || null;
} }
function matchesAuthTimeoutErrorPage(pathPattern) { function getAuthTimeoutErrorPageState(options = {}) {
if (!pathPattern.test(location.pathname || '')) return false; const { pathPatterns = [] } = options;
const path = location.pathname || '';
if (pathPatterns.length && !pathPatterns.some((pattern) => pattern.test(path))) {
return null;
}
const retryButton = getAuthRetryButton({ allowDisabled: true });
if (!retryButton) {
return null;
}
const text = getPageTextSnapshot(); const text = getPageTextSnapshot();
return Boolean( const titleMatched = AUTH_TIMEOUT_ERROR_TITLE_PATTERN.test(text)
getAuthRetryButton({ allowDisabled: true }) || AUTH_TIMEOUT_ERROR_TITLE_PATTERN.test(document.title || '');
&& (AUTH_TIMEOUT_ERROR_TITLE_PATTERN.test(text) const detailMatched = AUTH_TIMEOUT_ERROR_DETAIL_PATTERN.test(text);
|| AUTH_TIMEOUT_ERROR_DETAIL_PATTERN.test(text)
|| AUTH_TIMEOUT_ERROR_TITLE_PATTERN.test(document.title || '')) if (!titleMatched && !detailMatched) {
); return null;
}
return {
path,
url: location.href,
retryButton,
retryEnabled: isActionEnabled(retryButton),
titleMatched,
detailMatched,
};
}
function getSignupPasswordTimeoutErrorPageState() {
return getAuthTimeoutErrorPageState({
pathPatterns: [/\/create-account\/password(?:[/?#]|$)/i],
});
}
function getLoginTimeoutErrorPageState() {
return getAuthTimeoutErrorPageState({
pathPatterns: [/\/log-in(?:[/?#]|$)/i],
});
} }
function isSignupPasswordErrorPage() { function isSignupPasswordErrorPage() {
return matchesAuthTimeoutErrorPage(/\/create-account\/password(?:[/?#]|$)/i); return Boolean(getSignupPasswordTimeoutErrorPageState());
} }
function buildStep7RestartFromStep6Marker(reason, url = location.href) { function buildStep7RestartFromStep6Marker(reason, url = location.href) {
@@ -711,15 +739,16 @@ function buildStep7RestartFromStep6Marker(reason, url = location.href) {
} }
function getStep7RestartFromStep6Signal() { function getStep7RestartFromStep6Signal() {
if (!isLoginPage() || !matchesAuthTimeoutErrorPage(/\/log-in(?:[/?#]|$)/i)) { const timeoutPage = getLoginTimeoutErrorPageState();
if (!timeoutPage) {
return null; return null;
} }
return { return {
error: buildStep7RestartFromStep6Marker('login_timeout_error_page', location.href), error: buildStep7RestartFromStep6Marker('login_timeout_error_page', timeoutPage.url),
restartFromStep6: true, restartFromStep6: true,
reason: 'login_timeout_error_page', reason: 'login_timeout_error_page',
url: location.href, url: timeoutPage.url,
}; };
} }
@@ -737,9 +766,10 @@ function inspectSignupVerificationState() {
} }
if (isSignupPasswordErrorPage()) { if (isSignupPasswordErrorPage()) {
const timeoutPage = getSignupPasswordTimeoutErrorPageState();
return { return {
state: 'error', state: 'error',
retryButton: getAuthRetryButton({ allowDisabled: true }), retryButton: timeoutPage?.retryButton || null,
}; };
} }