()
| 1580 | |
| 1581 | private async init(): Promise<void> { |
| 1582 | if (this.db) return; |
| 1583 | |
| 1584 | this.baseDir = createDirectoryInAssets("ai"); |
| 1585 | this.file = path.join(this.baseDir, "config.json"); |
| 1586 | this.db = await JSONFilePreset<DB>(this.file, this.getDefaultConfig()); |
| 1587 | |
| 1588 | await this.writeQueue; |
| 1589 | await this.db.read(); |
| 1590 | this.currentConfig = { ...this.db.data }; |
| 1591 | const before = JSON.stringify(this.currentConfig); |
| 1592 | this.ensureDefaults(); |
| 1593 | const after = JSON.stringify(this.currentConfig); |
| 1594 | if (before !== after) { |
| 1595 | this.db.data = { ...this.currentConfig }; |
| 1596 | await this.db.write(); |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | getConfig(): DB { |
| 1601 | return { ...this.currentConfig }; |
| 1602 | } |
no test coverage detected