diff --git a/src/config/settings.ts b/src/config/settings.ts index f357e5a..769ba9c 100644 --- a/src/config/settings.ts +++ b/src/config/settings.ts @@ -31,28 +31,28 @@ export interface IccoderConfig { /** 环境配置 */ const ENV_CONFIG: Record = { - /** 本地开发环境 */ + /** 本地开发环境 - 通过 Gateway 路由 */ dev: { - backendUrl: "http://localhost:2233", - backendUrlStrongeLoop: "http://192.168.1.108:2029", + backendUrl: "http://localhost:8080/iccoder", + backendUrlStrongeLoop: "http://localhost:8080", loginUrl: "http://localhost/login", timeout: 300000, userId: "default-user", serviceTier: "max", // 默认使用 max }, - /** 测试服务器环境 */ + /** 测试服务器环境 - 通过 Gateway 路由 */ test: { - backendUrl: "http://192.168.1.108:2233", + backendUrl: "http://192.168.1.108:2029/iccoder", backendUrlStrongeLoop: "http://192.168.1.108:2029", loginUrl: "http://192.168.1.108:2005/login", timeout: 60000, userId: "default-user", serviceTier: "max", }, - /** 生产环境 */ + /** 生产环境 - 通过 Gateway 路由 */ prod: { - backendUrl: "https://api.iccoder.com", - backendUrlStrongeLoop: "http://api.iccoder.com:2029", + backendUrl: "https://api.iccoder.com/iccoder", + backendUrlStrongeLoop: "https://api.iccoder.com", loginUrl: "https://iccoder.com/login", timeout: 60000, userId: "default-user", diff --git a/src/extension.ts b/src/extension.ts index 81d90cf..e6c5f74 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -132,15 +132,18 @@ export function activate(context: vscode.ExtensionContext) { "ic-coder.login", async () => { try { - // 检查是否有现有 session - const existingSession = await vscode.authentication.getSession("iccoder", [], { createIfNone: false }); - if (existingSession) { - // 有旧 session,使用 forceNewSession 强制创建新 session - await vscode.authentication.getSession("iccoder", [], { forceNewSession: true }); - } else { - // 没有旧 session,使用 createIfNone 创建新 session - await vscode.authentication.getSession("iccoder", [], { createIfNone: true }); + // 先清除 session 偏好,避免 VSCode 弹出"账户不一致"确认框 + try { + await vscode.authentication.getSession("iccoder", [], { + clearSessionPreference: true, + createIfNone: false + }); + } catch { + // 忽略错误 } + + // 创建新 session + await vscode.authentication.getSession("iccoder", [], { createIfNone: true }); } catch (error) { vscode.window.showErrorMessage(`登录失败: ${error}`); } diff --git a/src/services/dialogService.ts b/src/services/dialogService.ts index 8bde83d..3eb3bed 100644 --- a/src/services/dialogService.ts +++ b/src/services/dialogService.ts @@ -1016,7 +1016,7 @@ export class DialogSession { if (selection === "去充值") { // 打开充值页面 vscode.env.openExternal( - vscode.Uri.parse("https://iccoder.com/memberCenter") + vscode.Uri.parse("https://iccoder.com/recharge") ); } }); diff --git a/src/services/sseHandler.ts b/src/services/sseHandler.ts index 1858965..e5828eb 100644 --- a/src/services/sseHandler.ts +++ b/src/services/sseHandler.ts @@ -238,6 +238,25 @@ export async function startStreamDialog( res.on('data', (chunk: string) => { if (!controller.aborted) { console.log('[SSE] 收到原始数据块:', chunk.substring(0, 200)); + + // 检查是否是业务错误码(Gateway 返回 HTTP 200 但响应体是错误 JSON) + try { + const trimmed = chunk.trim(); + if (trimmed.startsWith('{') && trimmed.includes('"code"')) { + const json = JSON.parse(trimmed); + if (json.code === 401 || json.msg?.includes('登录状态已过期')) { + console.log('[SSE] 检测到登录过期业务错误'); + const error = new Error('LOGIN_EXPIRED:登录状态已过期,请重新登录'); + callbacks.onError?.({ message: error.message }); + controller.abort(); + reject(error); + return; + } + } + } catch { + // 不是 JSON 格式,继续正常处理 + } + parser.feed(chunk); } }); diff --git a/src/views/ICViewProvider.ts b/src/views/ICViewProvider.ts index c028a2a..02eb3b6 100644 --- a/src/views/ICViewProvider.ts +++ b/src/views/ICViewProvider.ts @@ -128,10 +128,34 @@ export function showICHelperPanel(context: vscode.ExtensionContext) { * 侧边栏视图提供者 */ export class ICViewProvider implements vscode.WebviewViewProvider { + private _view?: vscode.WebviewView; + constructor( private readonly extensionUri: vscode.Uri, private readonly context: vscode.ExtensionContext - ) {} + ) { + // 监听认证状态变化 + this.context.subscriptions.push( + vscode.authentication.onDidChangeSessions((e) => { + if (e.provider.id === "iccoder") { + this.refreshLoginStatus(); + } + }) + ); + } + + /** + * 刷新登录状态并更新视图 + */ + private async refreshLoginStatus(): Promise { + if (this._view) { + const isLoggedIn = await this.checkLoginStatus(); + this._view.webview.html = this.getWebviewContent( + this._view.webview, + isLoggedIn + ); + } + } /** * 检查登录状态(使用 Authentication API) @@ -139,24 +163,29 @@ export class ICViewProvider implements vscode.WebviewViewProvider { private async checkLoginStatus(): Promise { try { const session = await vscode.authentication.getSession("iccoder", [], { createIfNone: false }); + console.log("[ICViewProvider] 检查登录状态, session:", session ? "存在" : "不存在"); if (!session) { return false; } // 检查 token 是否过期 const expired = isTokenExpired(session.accessToken); - // 如果已过期或无法判断(null),都认为未登录 - if (expired === true || expired === null) { - console.log("Token 已过期或无法判断过期状态"); + console.log("[ICViewProvider] token 过期检查结果:", expired); + // 只有明确过期才认为未登录,无法判断时认为已登录 + if (expired === true) { + console.log("[ICViewProvider] Token 已过期"); return false; } return true; } catch (error) { - console.log("检查登录状态失败:", error); + console.log("[ICViewProvider] 检查登录状态失败:", error); return false; } } resolveWebviewView(webviewView: vscode.WebviewView) { + // 保存引用以便后续刷新 + this._view = webviewView; + webviewView.webview.options = { enableScripts: true, localResourceRoots: [vscode.Uri.joinPath(this.extensionUri, "media")],