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