MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / sessionExists

Method sessionExists

apps/cli/src/sync/adapters.ts:61–91  ·  view source on GitHub ↗
(sessionId: string)

Source from the content-addressed store, hash-verified

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)) {

Callers 1

importFileMethod · 0.95

Calls 6

getDbPathMethod · 0.65
getMethod · 0.65
prepareMethod · 0.65
closeMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected