| 180 | } |
| 181 | |
| 182 | async init(): Promise<void> { |
| 183 | const baseDir = createDirectoryInAssets("deepwiki"); |
| 184 | const mainFile = path.join(baseDir, "config.json"); |
| 185 | const ctxFile = path.join(baseDir, "context.json"); |
| 186 | |
| 187 | this.dbMain = await JSONFilePreset<MainDB>(mainFile, { chats: {}, telegraphToken: "" }); |
| 188 | await this.dbMain.read(); |
| 189 | this.dbMain.data ||= { chats: {}, telegraphToken: "" }; |
| 190 | this.dbMain.data.chats ||= {}; |
| 191 | this.dbMain.data.telegraphToken ||= ""; |
| 192 | await this.dbMain.write(); |
| 193 | |
| 194 | this.dbCtx = await JSONFilePreset<CtxDB>(ctxFile, { chats: {} }); |
| 195 | await this.dbCtx.read(); |
| 196 | this.dbCtx.data ||= { chats: {} }; |
| 197 | this.dbCtx.data.chats ||= {}; |
| 198 | await this.dbCtx.write(); |
| 199 | } |
| 200 | |
| 201 | private ensureReady() { |
| 202 | if (!this.dbMain || !this.dbCtx) throw new Error("DeepWikiStore not initialized"); |