(
file: File | string,
options?: ImportOptions,
onProgress?: (p: ImportProgress) => void
)
| 23 | |
| 24 | export class ElectronImportAdapter implements ImportAdapter { |
| 25 | async importFile( |
| 26 | file: File | string, |
| 27 | options?: ImportOptions, |
| 28 | onProgress?: (p: ImportProgress) => void |
| 29 | ): Promise<ImportResult> { |
| 30 | const filePath = resolveFilePath(file) |
| 31 | if (!filePath) { |
| 32 | return { success: false, error: 'Cannot get file path in Electron' } |
| 33 | } |
| 34 | |
| 35 | return new Promise((resolve) => { |
| 36 | const unlisten = window.chatApi.onImportProgress((progress: any) => { |
| 37 | onProgress?.({ |
| 38 | stage: progress.stage || 'parsing', |
| 39 | progress: progress.percentage || progress.progress || 0, |
| 40 | message: progress.message || '', |
| 41 | bytesRead: progress.bytesRead, |
| 42 | totalBytes: progress.totalBytes, |
| 43 | messagesProcessed: progress.messagesProcessed, |
| 44 | }) |
| 45 | }) |
| 46 | |
| 47 | const importPromise = |
| 48 | options && (options.formatId || options.chatIndex !== undefined) |
| 49 | ? window.chatApi.importWithOptions(filePath, options as Record<string, unknown>) |
| 50 | : window.chatApi.import(filePath) |
| 51 | |
| 52 | importPromise |
| 53 | .then((result: any) => { |
| 54 | unlisten() |
| 55 | resolve({ |
| 56 | success: result.success, |
| 57 | sessionId: result.sessionId, |
| 58 | error: result.error, |
| 59 | diagnostics: result.diagnostics, |
| 60 | }) |
| 61 | }) |
| 62 | .catch((err: Error) => { |
| 63 | unlisten() |
| 64 | resolve({ success: false, error: err.message }) |
| 65 | }) |
| 66 | }) |
| 67 | } |
| 68 | |
| 69 | async detectFormat(file: File | string): Promise<FormatInfo | null> { |
| 70 | const filePath = resolveFilePath(file) |
nothing calls this directly
no test coverage detected