(sessionId: string)
| 59 | } |
| 60 | |
| 61 | sessionExists(sessionId: string): boolean { |
| 62 | const dbPath = this.dbManager.getDbPath(sessionId) |
| 63 | if (!fs.existsSync(dbPath)) return false |
| 64 | try { |
| 65 | const db = this.dbManager.openRawSessionDatabase(sessionId, { readonly: true }) |
| 66 | const row = db |
| 67 | .prepare("SELECT COUNT(*) as cnt FROM sqlite_master WHERE type='table' AND name='message'") |
| 68 | .get() as { cnt: number } |
| 69 | db.close() |
| 70 | if (row.cnt === 0) { |
| 71 | this.logger.warn(`[DirectImporter] DB file exists but has no message table: ${sessionId}, removing`) |
| 72 | try { |
| 73 | fs.unlinkSync(dbPath) |
| 74 | } catch { |
| 75 | /* ignore */ |
| 76 | } |
| 77 | return false |
| 78 | } |
| 79 | return true |
| 80 | } catch (error) { |
| 81 | if (error instanceof DataDirCompatibilityError) throw error |
| 82 | |
| 83 | this.logger.warn(`[DirectImporter] Cannot validate DB file: ${sessionId}, removing`) |
| 84 | try { |
| 85 | fs.unlinkSync(dbPath) |
| 86 | } catch { |
| 87 | /* ignore */ |
| 88 | } |
| 89 | return false |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | async importFile(tempFile: string, targetSessionId: string | undefined, externalId: string): Promise<ImportResult> { |
| 94 | if (targetSessionId && this.sessionExists(targetSessionId)) { |
no test coverage detected