Files
IC-Coder-Plugin/src/config/settings.ts
XiaoFeng 178f3a7498 feat: 从JWT解析userId并添加资源点余额提醒
- 新增 jwtUtils.ts 解析JWT token获取user_id
- dialogService 从登录session获取真实userId
- 添加 credit_update 事件处理
- 余额低于5点时弹窗提醒用户充值
- settings.ts 登录URL改为可配置
2026-01-09 15:53:54 +08:00

83 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 配置管理
* 支持 dev本地开发和 test测试服务器两种环境
*/
import * as vscode from "vscode";
/** 环境类型 */
type Environment = "dev" | "test" | "prod";
/** 当前环境 - 修改这里切换环境 */
const CURRENT_ENV: Environment = "dev";
/** 服务等级类型 */
export type ServiceTier = "lite" | "syntaxic" | "max" | "auto";
/** 配置项接口 */
export interface IccoderConfig {
/** 后端服务地址 */
backendUrl: string;
/** 登录页面地址 */
loginUrl: string;
/** 请求超时时间(毫秒) */
timeout: number;
/** 用户ID临时使用后续对接认证 */
userId: string;
/** 服务等级 */
serviceTier: ServiceTier;
}
/** 环境配置 */
const ENV_CONFIG: Record<Environment, IccoderConfig> = {
/** 本地开发环境 */
dev: {
backendUrl: "http://localhost:2233",
loginUrl: "http://localhost/login",
timeout: 300000,
userId: "default-user",
serviceTier: "max", // 默认使用 max
},
/** 测试服务器环境 */
test: {
backendUrl: "http://192.168.1.108:2233",
loginUrl: "http://192.168.1.108:2005/login",
timeout: 60000,
userId: "default-user",
serviceTier: "max",
},
/** 生产环境 */
prod: {
backendUrl: "https://api.iccoder.com",
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}`;
}