From c4c966f4090639ab6eb0c9bce650b3c9cd63d443 Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Sun, 26 Apr 2026 08:30:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20SUB2API=20?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E8=84=9A=E6=9C=AC=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E6=AD=A5=E9=AA=A4=2013=20=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=BC=BA=E6=97=A5=E5=BF=97=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/sub2api-panel.js | 9 +++++---- tests/sub2api-panel-proxy.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/content/sub2api-panel.js b/content/sub2api-panel.js index c078202..51d8bcd 100644 --- a/content/sub2api-panel.js +++ b/content/sub2api-panel.js @@ -1,4 +1,4 @@ -// content/sub2api-panel.js — 页内脚本:SUB2API 后台(步骤 1、9) +// content/sub2api-panel.js — 页内脚本:SUB2API 后台(OAuth 生成与回调提交) console.log('[MultiPage:sub2api-panel] Content script loaded on', location.href); @@ -69,6 +69,7 @@ async function handleStep(step, payload = {}) { return step1_generateOpenAiAuthUrl(payload); case 10: case 12: + case 13: return step9_submitOpenAiCallback({ ...(payload || {}), visibleStep: step }); default: throw new Error(`sub2api-panel.js 不处理步骤 ${step}`); @@ -530,11 +531,11 @@ async function step9_submitOpenAiCallback(payload = {}) { throw new Error('本次 localhost 回调中的 state 与步骤 1 生成的 state 不一致,请重新执行步骤 1。'); } - log('步骤 10:正在向 SUB2API 交换 OpenAI 授权码...'); + log(`步骤 ${visibleStep}:正在向 SUB2API 交换 OpenAI 授权码...`); if (proxy) { - log(`步骤 10:使用 SUB2API 默认代理 ${buildProxyDisplayName(proxy)}。`); + log(`步骤 ${visibleStep}:使用 SUB2API 默认代理 ${buildProxyDisplayName(proxy)}。`); } else { - log('步骤 10:未配置 SUB2API 默认代理,本次将不使用代理。'); + log(`步骤 ${visibleStep}:未配置 SUB2API 默认代理,本次将不使用代理。`); } const exchangeRequestBody = { session_id: sessionId, diff --git a/tests/sub2api-panel-proxy.test.js b/tests/sub2api-panel-proxy.test.js index c12fc38..a7b23c3 100644 --- a/tests/sub2api-panel-proxy.test.js +++ b/tests/sub2api-panel-proxy.test.js @@ -177,6 +177,31 @@ test('SUB2API step 10 uses the same proxy for code exchange and account creation assert.equal(context.completed[0].step, 10); }); +test('SUB2API panel accepts Plus platform verify step 13', async () => { + const fetchCalls = []; + const context = createSub2ApiPanelContext(fetchCalls); + + await vm.runInContext(` + handleStep(13, { + localhostUrl: 'http://localhost:1455/auth/callback?code=callback-code&state=oauth-state', + sub2apiUrl: 'https://sub.example/admin/accounts', + sub2apiEmail: 'admin@example.com', + sub2apiPassword: 'secret', + sub2apiGroupName: 'codex', + sub2apiSessionId: 'session-1', + sub2apiOAuthState: 'oauth-state', + sub2apiGroupId: 5 + }) + `, context); + + const exchangeCall = fetchCalls.find((call) => call.path === '/api/v1/admin/openai/exchange-code'); + const createCall = fetchCalls.find((call) => call.path === '/api/v1/admin/accounts'); + + assert.equal(exchangeCall.body.code, 'callback-code'); + assert.equal(createCall.body.group_ids[0], 5); + assert.equal(context.completed[0].step, 13); +}); + test('SUB2API step 1 omits proxy_id when default proxy is empty', async () => { const fetchCalls = []; const context = createSub2ApiPanelContext(fetchCalls);