Refactor multi-flow mail capability boundaries

This commit is contained in:
QLHazyCoder
2026-05-13 06:35:43 +08:00
parent a85ed0ce89
commit d93cdfff9e
33 changed files with 2035 additions and 198 deletions
+64 -1
View File
@@ -74,6 +74,44 @@
}
return method === 'phone' && canUsePhoneSignup(state) ? 'phone' : 'email';
},
validateAutoRunStart = (state = {}, options = {}) => {
const validationState = options?.state || state;
const rootScope = typeof self !== 'undefined' ? self : globalThis;
const capabilityRegistry = rootScope.MultiPageFlowCapabilities?.createFlowCapabilityRegistry?.({
defaultFlowId: 'openai',
}) || null;
if (!capabilityRegistry?.validateAutoRunStart) {
return { ok: true, errors: [] };
}
return capabilityRegistry.validateAutoRunStart({
activeFlowId: options?.activeFlowId ?? validationState?.activeFlowId,
panelMode: options?.panelMode ?? validationState?.panelMode,
signupMethod: options?.signupMethod ?? validationState?.signupMethod,
state: validationState,
});
},
validateModeSwitch = (state = {}, options = {}) => {
const validationState = options?.state || state;
const rootScope = typeof self !== 'undefined' ? self : globalThis;
const capabilityRegistry = rootScope.MultiPageFlowCapabilities?.createFlowCapabilityRegistry?.({
defaultFlowId: 'openai',
}) || null;
if (!capabilityRegistry?.validateModeSwitch) {
return {
ok: true,
changedKeys: Array.isArray(options?.changedKeys) ? options.changedKeys : [],
errors: [],
normalizedUpdates: {},
};
}
return capabilityRegistry.validateModeSwitch({
activeFlowId: options?.activeFlowId ?? validationState?.activeFlowId,
changedKeys: options?.changedKeys,
panelMode: options?.panelMode ?? validationState?.panelMode,
signupMethod: options?.signupMethod ?? validationState?.signupMethod,
state: validationState,
});
},
getTabId,
getStopRequested,
handleAutoRunLoopUnhandledError,
@@ -908,6 +946,10 @@
}
}
const state = await getState();
const autoRunStartValidation = validateAutoRunStart(state, { state });
if (autoRunStartValidation?.ok === false) {
throw new Error(autoRunStartValidation.errors?.[0]?.message || '当前设置不支持启动自动流程。');
}
if (getPendingAutoRunTimerPlan(state)) {
throw new Error('已有自动运行倒计时计划,请先取消或立即开始。');
}
@@ -935,6 +977,11 @@
});
}
}
const state = await getState();
const autoRunStartValidation = validateAutoRunStart(state, { state });
if (autoRunStartValidation?.ok === false) {
throw new Error(autoRunStartValidation.errors?.[0]?.message || '当前设置不支持启动自动流程。');
}
const totalRuns = normalizeRunCount(message.payload?.totalRuns || 1);
return await scheduleAutoRun(totalRuns, {
delayMinutes: message.payload?.delayMinutes,
@@ -1006,6 +1053,16 @@
const currentState = await getState();
const updates = buildPersistentSettingsPayload(message.payload || {});
const sessionUpdates = buildLuckmailSessionSettingsPayload(message.payload || {});
const modeValidation = validateModeSwitch({
...currentState,
...updates,
resolvedSignupMethod: null,
}, {
changedKeys: Object.keys(updates),
});
if (modeValidation?.normalizedUpdates && Object.keys(modeValidation.normalizedUpdates).length > 0) {
Object.assign(updates, modeValidation.normalizedUpdates);
}
const nextSignupState = {
...currentState,
...updates,
@@ -1017,6 +1074,7 @@
|| Object.prototype.hasOwnProperty.call(updates, 'signupMethod')
|| Object.prototype.hasOwnProperty.call(updates, 'panelMode')
|| Object.prototype.hasOwnProperty.call(updates, 'activeFlowId')
|| Object.prototype.hasOwnProperty.call(updates, 'contributionMode')
) {
updates.signupMethod = resolveSignupMethod(nextSignupState);
}
@@ -1117,7 +1175,12 @@
);
await addLog(`Plus 支付方式已切换为 ${selectedPlusPaymentMethod},已更新对应的 Plus 步骤。`, 'info');
}
return { ok: true, state: await getState(), proxyRouting };
return {
ok: true,
modeValidation,
proxyRouting,
state: await getState(),
};
}
case 'REFRESH_GPC_CARD_BALANCE': {
+12 -17
View File
@@ -412,27 +412,22 @@
if (typeof externalBuildVerificationPollPayload === 'function') {
return externalBuildVerificationPollPayload(step, state, overrides);
}
const normalizedStep = Number(step) === 4 ? 4 : 8;
const is2925Provider = state?.mailProvider === '2925';
const mail2925MatchTargetEmail = is2925Provider
&& String(state?.mail2925Mode || '').trim().toLowerCase() === 'receive';
if (step === 4) {
return {
filterAfterTimestamp: is2925Provider ? 0 : getHotmailVerificationRequestTimestamp(4, state),
senderFilters: ['openai', 'noreply', 'verify', 'auth', 'duckduckgo', 'forward'],
subjectFilters: ['verify', 'verification', 'code', '验证码', 'confirm'],
targetEmail: state.email,
mail2925MatchTargetEmail,
maxAttempts: is2925Provider ? MAIL_2925_VERIFICATION_MAX_ATTEMPTS : 5,
intervalMs: is2925Provider ? MAIL_2925_VERIFICATION_INTERVAL_MS : 3000,
...overrides,
};
}
return {
filterAfterTimestamp: is2925Provider ? 0 : getHotmailVerificationRequestTimestamp(8, state),
senderFilters: ['openai', 'noreply', 'verify', 'auth', 'chatgpt', 'duckduckgo', 'forward'],
subjectFilters: ['verify', 'verification', 'code', '验证码', 'confirm', 'login'],
targetEmail: String(state?.step8VerificationTargetEmail || '').trim() || state.email,
flowId: String(state?.activeFlowId || '').trim(),
step: normalizedStep,
filterAfterTimestamp: is2925Provider ? 0 : getHotmailVerificationRequestTimestamp(normalizedStep, state),
senderFilters: [],
subjectFilters: [],
requiredKeywords: [],
codePatterns: [],
targetEmail: normalizedStep === 4
? state.email
: (String(state?.step8VerificationTargetEmail || '').trim() || state.email),
targetEmailHints: [],
mail2925MatchTargetEmail,
maxAttempts: is2925Provider ? MAIL_2925_VERIFICATION_MAX_ATTEMPTS : 5,
intervalMs: is2925Provider ? MAIL_2925_VERIFICATION_INTERVAL_MS : 3000,