feat: 删除冗余代码,并修复可能出现的BUG

This commit is contained in:
foxhui
2025-12-09 19:46:13 +08:00
Unverified
parent e13c7092af
commit 801eb74b24
11 changed files with 1005 additions and 944 deletions
+8
View File
@@ -6,6 +6,9 @@ import { logger } from './logger.js';
const CONFIG_PATH = path.join(process.cwd(), 'config.yaml');
// 模块级缓存,确保配置只从磁盘读取一次
let cachedConfig = null;
/**
* 生成随机 API Key
* 格式: sk-{48位十六进制字符}
@@ -97,6 +100,9 @@ browser:
* @returns {object} 配置对象
*/
export function loadConfig() {
// 如果已有缓存,直接返回
if (cachedConfig) return cachedConfig;
try {
if (!fs.existsSync(CONFIG_PATH)) {
logger.warn('配置器', '配置文件不存在,正在生成默认配置...');
@@ -174,6 +180,8 @@ export function loadConfig() {
logger.setLevel(config.logLevel);
}
// 缓存配置
cachedConfig = config;
return config;
} catch (e) {
logger.error('配置器', '无法加载或生成配置文件', { error: e.message });