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

Method sessionExists

apps/desktop/main/api/adapters.ts:88–118  ·  view source on GitHub ↗
(sessionId: string)

Source from the content-addressed store, hash-verified

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

Callers 1

importFileMethod · 0.95

Calls 8

getPathProviderFunction · 0.90
getDesktopAppVersionFunction · 0.90
getVersionMethod · 0.65
getMethod · 0.65
prepareMethod · 0.65
closeMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected