| 231 | super(); |
| 232 | this.init().catch(console.error); |
| 233 | } |
| 234 | |
| 235 | private async init() { |
| 236 | this.baseDir = createDirectoryInAssets('xmsl'); |
| 237 | const configPath = path.join(this.baseDir, 'config.json'); |
| 238 | this.db = await JSONFilePreset<XMSLConfig>(configPath, this.config); |
| 239 | this.config = this.db.data; |
| 240 | |
| 241 | // 从环境变量加载配置 |
| 242 | if (!this.config.apiKey && process.env.XMSL_API_KEY) { |
| 243 | this.config.apiKey = process.env.XMSL_API_KEY; |
| 244 | } |
| 245 | if (!this.config.baseUrl && process.env.XMSL_BASE_URL) { |
| 246 | this.config.baseUrl = process.env.XMSL_BASE_URL; |
| 247 | } |
| 248 | if (!this.config.model && process.env.XMSL_MODEL) { |
| 249 | this.config.model = process.env.XMSL_MODEL.toLowerCase(); |
| 250 | } |
| 251 | if (!this.config.apiMode && process.env.XMSL_API_MODE) { |
| 252 | this.config.apiMode = (process.env.XMSL_API_MODE.toLowerCase() as APIMode); |
| 253 | } |
| 254 | |
| 255 | await this.saveConfig(); |
| 256 | } |
| 257 | |