@@ -57,6 +57,8 @@ export class DatabaseManager {
5757 type TEXT NOT NULL,
5858 text TEXT,
5959 image TEXT,
60+ file_path TEXT,
61+ file_name TEXT,
6062 timestamp INTEGER NOT NULL,
6163 embedding BLOB,
6264 created_at DATETIME DEFAULT CURRENT_TIMESTAMP
@@ -71,6 +73,8 @@ export class DatabaseManager {
7173 type TEXT NOT NULL,
7274 text TEXT,
7375 image TEXT,
76+ file_path TEXT,
77+ file_name TEXT,
7478 timestamp INTEGER NOT NULL,
7579 embedding BLOB,
7680 archived_at DATETIME DEFAULT CURRENT_TIMESTAMP,
@@ -81,15 +85,45 @@ export class DatabaseManager {
8185 CREATE INDEX IF NOT EXISTS idx_archived_at ON archived_items(archived_at DESC);
8286 CREATE INDEX IF NOT EXISTS idx_archived_type ON archived_items(type);
8387 ` ) ;
88+
89+ // Add columns to existing tables if they don't exist
90+ try {
91+ this . db . exec ( `ALTER TABLE clipboard_items ADD COLUMN file_path TEXT` ) ;
92+ log . info ( "Added file_path column to clipboard_items" ) ;
93+ } catch ( error ) {
94+ // Column already exists, ignore
95+ }
96+
97+ try {
98+ this . db . exec ( `ALTER TABLE clipboard_items ADD COLUMN file_name TEXT` ) ;
99+ log . info ( "Added file_name column to clipboard_items" ) ;
100+ } catch ( error ) {
101+ // Column already exists, ignore
102+ }
103+
104+ try {
105+ this . db . exec ( `ALTER TABLE archived_items ADD COLUMN file_path TEXT` ) ;
106+ log . info ( "Added file_path column to archived_items" ) ;
107+ } catch ( error ) {
108+ // Column already exists, ignore
109+ }
110+
111+ try {
112+ this . db . exec ( `ALTER TABLE archived_items ADD COLUMN file_name TEXT` ) ;
113+ log . info ( "Added file_name column to archived_items" ) ;
114+ } catch ( error ) {
115+ // Column already exists, ignore
116+ }
117+
84118 log . info ( "Database tables initialized" ) ;
85119 }
86120
87121 addItem ( item : Omit < ClipboardItem , "id" > ) : number {
88122 // If embedding exists, insert with vec_f32, otherwise insert without it
89123 if ( item . embedding && item . embedding . length > 0 ) {
90124 const stmt = this . db . prepare ( `
91- INSERT INTO clipboard_items (type, text, image, timestamp, embedding)
92- VALUES (?, ?, ?, ?, vec_f32(?))
125+ INSERT INTO clipboard_items (type, text, image, file_path, file_name, timestamp, embedding)
126+ VALUES (?, ?, ?, ?, ?, ?, vec_f32(?))
93127 ` ) ;
94128
95129 const embeddingBlob = Buffer . from (
@@ -100,21 +134,25 @@ export class DatabaseManager {
100134 item . type ,
101135 item . text || null ,
102136 item . image || null ,
137+ item . filePath || null ,
138+ item . fileName || null ,
103139 item . timestamp ,
104140 embeddingBlob
105141 ) ;
106142
107143 return result . lastInsertRowid as number ;
108144 } else {
109145 const stmt = this . db . prepare ( `
110- INSERT INTO clipboard_items (type, text, image, timestamp)
111- VALUES (?, ?, ?, ?)
146+ INSERT INTO clipboard_items (type, text, image, file_path, file_name, timestamp)
147+ VALUES (?, ?, ?, ?, ?, ? )
112148 ` ) ;
113149
114150 const result = stmt . run (
115151 item . type ,
116152 item . text || null ,
117153 item . image || null ,
154+ item . filePath || null ,
155+ item . fileName || null ,
118156 item . timestamp
119157 ) ;
120158
@@ -124,7 +162,7 @@ export class DatabaseManager {
124162
125163 getItems ( limit : number = 1000 , offset : number = 0 ) : ClipboardItem [ ] {
126164 const stmt = this . db . prepare ( `
127- SELECT id, type, text, image, timestamp
165+ SELECT id, type, text, image, file_path as filePath, file_name as fileName, timestamp
128166 FROM clipboard_items
129167 ORDER BY timestamp DESC
130168 LIMIT ? OFFSET ?
@@ -135,7 +173,7 @@ export class DatabaseManager {
135173
136174 getItemById ( id : number ) : ClipboardItem | undefined {
137175 const stmt = this . db . prepare ( `
138- SELECT id, type, text, image, timestamp
176+ SELECT id, type, text, image, file_path as filePath, file_name as fileName, timestamp
139177 FROM clipboard_items
140178 WHERE id = ?
141179 ` ) ;
@@ -172,7 +210,7 @@ export class DatabaseManager {
172210
173211 searchItems ( query : string , limit : number = 100 ) : ClipboardItem [ ] {
174212 const stmt = this . db . prepare ( `
175- SELECT id, type, text, image, timestamp
213+ SELECT id, type, text, image, file_path as filePath, file_name as fileName, timestamp
176214 FROM clipboard_items
177215 WHERE text LIKE ?
178216 ORDER BY timestamp DESC
@@ -197,6 +235,8 @@ export class DatabaseManager {
197235 type,
198236 text,
199237 image,
238+ file_path as filePath,
239+ file_name as fileName,
200240 timestamp,
201241 vec_distance_cosine(embedding, vec_f32(?)) as distance
202242 FROM clipboard_items
@@ -212,8 +252,8 @@ export class DatabaseManager {
212252 const cutoffTimestamp = Date . now ( ) - retentionDays * 24 * 60 * 60 * 1000 ;
213253
214254 const insertStmt = this . db . prepare ( `
215- INSERT INTO archived_items (original_id, type, text, image, timestamp, embedding, created_at)
216- SELECT id, type, text, image, timestamp, embedding, created_at
255+ INSERT INTO archived_items (original_id, type, text, image, file_path, file_name, timestamp, embedding, created_at)
256+ SELECT id, type, text, image, file_path, file_name, timestamp, embedding, created_at
217257 FROM clipboard_items
218258 WHERE timestamp < ?
219259 ` ) ;
@@ -235,7 +275,7 @@ export class DatabaseManager {
235275
236276 getArchivedItems ( limit : number = 1000 , offset : number = 0 ) : ClipboardItem [ ] {
237277 const stmt = this . db . prepare ( `
238- SELECT id, type, text, image, timestamp
278+ SELECT id, type, text, image, file_path as filePath, file_name as fileName, timestamp
239279 FROM archived_items
240280 ORDER BY timestamp DESC
241281 LIMIT ? OFFSET ?
@@ -246,8 +286,8 @@ export class DatabaseManager {
246286
247287 unarchiveItem ( id : number ) : boolean {
248288 const insertStmt = this . db . prepare ( `
249- INSERT INTO clipboard_items (type, text, image, timestamp, embedding)
250- SELECT type, text, image, timestamp, embedding
289+ INSERT INTO clipboard_items (type, text, image, file_path, file_name, timestamp, embedding)
290+ SELECT type, text, image, file_path, file_name, timestamp, embedding
251291 FROM archived_items
252292 WHERE id = ?
253293 ` ) ;
@@ -306,6 +346,8 @@ export class DatabaseManager {
306346 type,
307347 text,
308348 image,
349+ file_path as filePath,
350+ file_name as fileName,
309351 timestamp,
310352 vec_distance_cosine(embedding, vec_f32(?)) as distance
311353 FROM archived_items
0 commit comments