* 调度 per-account daily stats 持久化(debounce 5 秒) * 高频 accumulateStats 调用合并为单次 I/O——重复调用替换上一个 timer * dataSaveMode='none' 时不写盘,返回 false * @param {string} email - 邮箱 * @param {Object} stats - 完整 stats 对象 { chat: {input,output}, cli: {calls,input,output} } * @returns {boolean} 是否调度成功
(email, stats)
| 298 | */ |
| 299 | async _saveAllToFile(accounts) { |
| 300 | return enqueueFileTask(async () => { |
| 301 | const data = await this._readDataFile() |
| 302 | |
| 303 | data.accounts = accounts.map(account => ({ |
| 304 | email: account.email, |
| 305 | password: account.password, |
| 306 | token: account.token, |
| 307 | expires: account.expires, |
| 308 | proxy: account.proxy ?? null, |
| 309 | stats: account.stats ?? undefined, |
| 310 | statsHistory: account.statsHistory ?? undefined, |
| 311 | fingerprint: account.fingerprint ?? undefined |
| 312 | })) |
| 313 | |
| 314 | await this._writeDataFile(data) |
| 315 | return true |
| 316 | }) |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * 调度 per-account daily stats 持久化(debounce 5 秒) |
| 321 | * 高频 accumulateStats 调用合并为单次 I/O——重复调用替换上一个 timer |
| 322 | * dataSaveMode='none' 时不写盘,返回 false |
| 323 | * @param {string} email - 邮箱 |
| 324 | * @param {Object} stats - 完整 stats 对象 { chat: {input,output}, cli: {calls,input,output} } |
| 325 | * @returns {boolean} 是否调度成功 |
| 326 | */ |
| 327 | saveAccountStats(email, stats) { |
| 328 | if (config.dataSaveMode === 'none') { |
| 329 | return false |
| 330 | } |
no test coverage detected