Fix dynamic platform verify step mapping
This commit is contained in:
+4
-2
@@ -13585,6 +13585,7 @@ const step10Executor = self.MultiPageBackgroundStep10?.createStep10Executor({
|
||||
ensureContentScriptReadyOnTab,
|
||||
getPanelMode,
|
||||
getTabId,
|
||||
getStepIdByKeyForState,
|
||||
isLocalhostOAuthCallbackUrl,
|
||||
isTabAlive,
|
||||
normalizeCodex2ApiUrl,
|
||||
@@ -15020,7 +15021,7 @@ async function prepareStep8DebuggerClick(tabId, options = {}) {
|
||||
const result = await sendToContentScriptResilient('signup-page', {
|
||||
type: 'STEP8_FIND_AND_CLICK',
|
||||
source: 'background',
|
||||
payload: { visibleStep },
|
||||
payload: { visibleStep, nodeId: 'confirm-oauth' },
|
||||
}, {
|
||||
timeoutMs,
|
||||
responseTimeoutMs,
|
||||
@@ -15051,6 +15052,7 @@ async function triggerStep8ContentStrategy(tabId, strategy, options = {}) {
|
||||
type: 'STEP8_TRIGGER_CONTINUE',
|
||||
source: 'background',
|
||||
payload: {
|
||||
nodeId: 'confirm-oauth',
|
||||
visibleStep,
|
||||
strategy,
|
||||
findTimeoutMs: 4000,
|
||||
@@ -15087,7 +15089,7 @@ async function recoverAuthRetryPageOnTab(tabId, payload = {}, options = {}) {
|
||||
const result = await sendToContentScriptResilient('signup-page', {
|
||||
type: 'RECOVER_AUTH_RETRY_PAGE',
|
||||
source: 'background',
|
||||
payload,
|
||||
payload: { nodeId: 'confirm-oauth', ...(payload || {}) },
|
||||
}, {
|
||||
timeoutMs,
|
||||
responseTimeoutMs,
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
ensureContentScriptReadyOnTab,
|
||||
getPanelMode,
|
||||
getTabId,
|
||||
getStepIdByKeyForState,
|
||||
isLocalhostOAuthCallbackUrl,
|
||||
isTabAlive,
|
||||
normalizeCodex2ApiUrl,
|
||||
@@ -51,11 +52,31 @@
|
||||
return visibleStep >= 10 ? visibleStep : 10;
|
||||
}
|
||||
|
||||
function resolveConfirmOauthStep(platformVerifyStep = 10) {
|
||||
return Number(platformVerifyStep) >= 13 ? 12 : 9;
|
||||
function resolveStepIdByKey(state = {}, stepKey = '') {
|
||||
if (typeof getStepIdByKeyForState !== 'function') {
|
||||
return null;
|
||||
}
|
||||
const step = Number(getStepIdByKeyForState(stepKey, state));
|
||||
return Number.isInteger(step) && step > 0 ? step : null;
|
||||
}
|
||||
|
||||
function resolveAuthLoginStep(platformVerifyStep = 10) {
|
||||
function resolveConfirmOauthStep(platformVerifyStep = 10, state = {}) {
|
||||
const dynamicStep = resolveStepIdByKey(state, 'confirm-oauth');
|
||||
if (dynamicStep && dynamicStep < Number(platformVerifyStep)) {
|
||||
return dynamicStep;
|
||||
}
|
||||
return Math.max(1, Number(platformVerifyStep) - 1);
|
||||
}
|
||||
|
||||
function resolveAuthLoginStep(platformVerifyStep = 10, state = {}) {
|
||||
const reloginStep = resolveStepIdByKey(state, 'relogin-bound-email');
|
||||
if (reloginStep && reloginStep < Number(platformVerifyStep)) {
|
||||
return reloginStep;
|
||||
}
|
||||
const oauthLoginStep = resolveStepIdByKey(state, 'oauth-login');
|
||||
if (oauthLoginStep && oauthLoginStep < Number(platformVerifyStep)) {
|
||||
return oauthLoginStep;
|
||||
}
|
||||
return Number(platformVerifyStep) >= 13 ? 10 : 7;
|
||||
}
|
||||
|
||||
@@ -63,8 +84,8 @@
|
||||
return addLog(message, level, { step, stepKey: 'platform-verify' });
|
||||
}
|
||||
|
||||
function parseLocalhostCallback(rawUrl, platformVerifyStep = 10) {
|
||||
const confirmOauthStep = resolveConfirmOauthStep(platformVerifyStep);
|
||||
function parseLocalhostCallback(rawUrl, platformVerifyStep = 10, state = {}) {
|
||||
const confirmOauthStep = resolveConfirmOauthStep(platformVerifyStep, state);
|
||||
let parsed;
|
||||
try {
|
||||
parsed = new URL(rawUrl);
|
||||
@@ -239,8 +260,8 @@
|
||||
|
||||
async function executeCpaStep10(state) {
|
||||
const platformVerifyStep = resolvePlatformVerifyStep(state);
|
||||
const confirmOauthStep = resolveConfirmOauthStep(platformVerifyStep);
|
||||
const authLoginStep = resolveAuthLoginStep(platformVerifyStep);
|
||||
const confirmOauthStep = resolveConfirmOauthStep(platformVerifyStep, state);
|
||||
const authLoginStep = resolveAuthLoginStep(platformVerifyStep, state);
|
||||
if (state.localhostUrl && !isLocalhostOAuthCallbackUrl(state.localhostUrl)) {
|
||||
throw new Error(`步骤 ${confirmOauthStep} 捕获到的 localhost OAuth 回调地址无效,请重新执行步骤 ${confirmOauthStep}。`);
|
||||
}
|
||||
@@ -260,7 +281,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const callback = parseLocalhostCallback(state.localhostUrl, platformVerifyStep);
|
||||
const callback = parseLocalhostCallback(state.localhostUrl, platformVerifyStep, state);
|
||||
const expectedState = normalizeString(state.cpaOAuthState);
|
||||
if (expectedState && expectedState !== callback.state) {
|
||||
throw new Error(`CPA 回调 state 与当前授权会话不匹配,请重新执行步骤 ${authLoginStep}。`);
|
||||
@@ -299,8 +320,8 @@
|
||||
|
||||
async function executeCodex2ApiStep10(state) {
|
||||
const platformVerifyStep = resolvePlatformVerifyStep(state);
|
||||
const confirmOauthStep = resolveConfirmOauthStep(platformVerifyStep);
|
||||
const authLoginStep = resolveAuthLoginStep(platformVerifyStep);
|
||||
const confirmOauthStep = resolveConfirmOauthStep(platformVerifyStep, state);
|
||||
const authLoginStep = resolveAuthLoginStep(platformVerifyStep, state);
|
||||
if (state.localhostUrl && !isLocalhostOAuthCallbackUrl(state.localhostUrl)) {
|
||||
throw new Error(`步骤 ${confirmOauthStep} 捕获到的 localhost OAuth 回调地址无效,请重新执行步骤 ${confirmOauthStep}。`);
|
||||
}
|
||||
@@ -314,7 +335,7 @@
|
||||
throw new Error('尚未配置 Codex2API 管理密钥,请先在侧边栏填写。');
|
||||
}
|
||||
|
||||
const callback = parseLocalhostCallback(state.localhostUrl, platformVerifyStep);
|
||||
const callback = parseLocalhostCallback(state.localhostUrl, platformVerifyStep, state);
|
||||
const expectedState = normalizeString(state.codex2apiOAuthState);
|
||||
if (expectedState && expectedState !== callback.state) {
|
||||
throw new Error(`Codex2API 回调 state 与当前授权会话不匹配,请重新执行步骤 ${authLoginStep}。`);
|
||||
@@ -345,7 +366,7 @@
|
||||
async function executeSub2ApiStep10(state) {
|
||||
const platformVerifyStep = resolvePlatformVerifyStep(state);
|
||||
const visibleStep = platformVerifyStep;
|
||||
const confirmOauthStep = resolveConfirmOauthStep(visibleStep);
|
||||
const confirmOauthStep = resolveConfirmOauthStep(visibleStep, state);
|
||||
if (state.localhostUrl && !isLocalhostOAuthCallbackUrl(state.localhostUrl)) {
|
||||
throw new Error(`步骤 ${confirmOauthStep} 捕获到的 localhost OAuth 回调地址无效,请重新执行步骤 ${confirmOauthStep}。`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user