/** * 配置管理 * 支持 dev(本地开发)和 test(测试服务器)两种环境 */ import * as vscode from "vscode"; /** 环境类型 */ type Environment = "dev" | "test" | "prod"; /** 当前环境 - 修改这里切换环境 */ const CURRENT_ENV: Environment = "test"; /** 服务等级类型 */ export type ServiceTier = "lite" | "syntaxic" | "max" | "auto"; /** 配置项接口 */ export interface IccoderConfig { /** 后端服务地址 */ backendUrl: string; /** 登录页面地址 */ loginUrl: string; /** 后端服务地址(strangeLoop) */ backendUrlStrongeLoop: string; /** 请求超时时间(毫秒) */ timeout: number; /** 用户ID(临时使用,后续对接认证) */ userId: string; /** 服务等级 */ serviceTier: ServiceTier; } /** 环境配置 */ const ENV_CONFIG: Record = { /** 本地开发环境 - 通过 Gateway 路由 */ dev: { 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.134:2233", backendUrlStrongeLoop: "http://192.168.1.134:2233", loginUrl: "http://192.168.1.134/login", timeout: 60000, userId: "default-user", serviceTier: "max", }, /** 生产环境 - 通过 Gateway 路由 */ prod: { backendUrl: "https://api.iccoder.com", backendUrlStrongeLoop: "http://192.168.1.115:2029", loginUrl: "https://iccoder.com/login", timeout: 60000, userId: "default-user", serviceTier: "auto", }, }; /** * 获取当前环境 */ export function getCurrentEnv(): Environment { return CURRENT_ENV; } /** * 获取配置项 */ export function getConfig(): IccoderConfig { return { ...ENV_CONFIG[CURRENT_ENV] }; } /** * 获取后端 API 地址 */ export function getApiUrl(path: string): string { const { backendUrl } = getConfig(); const baseUrl = backendUrl.endsWith("/") ? backendUrl.slice(0, -1) : backendUrl; const apiPath = path.startsWith("/") ? path : `/${path}`; return `${baseUrl}${apiPath}`; } /** * 获取 StrangeLoop 服务 API 地址(用于用户信息等) */ export function getStrangeLoopApiUrl(path: string): string { const { backendUrlStrongeLoop } = getConfig(); const baseUrl = backendUrlStrongeLoop.endsWith("/") ? backendUrlStrongeLoop.slice(0, -1) : backendUrlStrongeLoop; const apiPath = path.startsWith("/") ? path : `/${path}`; return `${baseUrl}${apiPath}`; }