(sessionId: string)
| 86 | } |
| 87 | |
| 88 | sessionExists(sessionId: string): boolean { |
| 89 | assertDesktopDataDirCompatible(getPathProvider(), getDesktopAppVersion(app.getVersion())) |
| 90 | |
| 91 | const dbPath = path.join(worker.getDbDirectory(), `${sessionId}.db`) |
| 92 | if (!fs.existsSync(dbPath)) return false |
| 93 | try { |
| 94 | const db = new Database(dbPath, { readonly: true }) |
| 95 | const row = db |
| 96 | .prepare("SELECT COUNT(*) as cnt FROM sqlite_master WHERE type='table' AND name='message'") |
| 97 | .get() as { cnt: number } |
| 98 | db.close() |
| 99 | if (row.cnt === 0) { |
| 100 | this.logger.warn(`[Pull] DB file exists but has no message table: ${sessionId}, removing`) |
| 101 | try { |
| 102 | fs.unlinkSync(dbPath) |
| 103 | } catch { |
| 104 | /* ignore */ |
| 105 | } |
| 106 | return false |
| 107 | } |
| 108 | return true |
| 109 | } catch { |
| 110 | this.logger.warn(`[Pull] Cannot validate DB file: ${sessionId}, removing`) |
| 111 | try { |
| 112 | fs.unlinkSync(dbPath) |
| 113 | } catch { |
| 114 | /* ignore */ |
| 115 | } |
| 116 | return false |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | async importFile(tempFile: string, targetSessionId: string | undefined, externalId: string): Promise<ImportResult> { |
| 121 | if (targetSessionId && this.sessionExists(targetSessionId)) { |
no test coverage detected