( filePath: string, onProgress?: (progress: ParseProgress) => void, formatOptions?: Record<string, unknown>, externalSessionId?: string )
| 516 | * @param formatOptions 格式特定选项(如 Telegram 的 chatIndex) |
| 517 | */ |
| 518 | export async function streamImport( |
| 519 | filePath: string, |
| 520 | onProgress?: (progress: ParseProgress) => void, |
| 521 | formatOptions?: Record<string, unknown>, |
| 522 | externalSessionId?: string |
| 523 | ): Promise<StreamImportResult> { |
| 524 | assertDataDirCompatibleNow() |
| 525 | |
| 526 | const result = await sendToWorkerWithProgress<StreamImportResult>( |
| 527 | 'streamImport', |
| 528 | { filePath, formatOptions, externalSessionId }, |
| 529 | onProgress |
| 530 | ) |
| 531 | if (!result.success || !result.sessionId) return result |
| 532 | |
| 533 | try { |
| 534 | raiseChatDbCompatibilityGate(getPathProvider(), { |
| 535 | version: getDesktopAppVersion(app.getVersion()), |
| 536 | kind: 'desktop', |
| 537 | }) |
| 538 | } catch (error) { |
| 539 | deleteImportedSessionFiles(result.sessionId) |
| 540 | return { |
| 541 | success: false, |
| 542 | error: error instanceof Error ? error.message : String(error), |
| 543 | diagnostics: result.diagnostics, |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | return result |
| 548 | } |
| 549 | |
| 550 | function deleteImportedSessionFiles(sessionId: string): void { |
| 551 | const dbPath = path.join(getDbDir(), `${sessionId}.db`) |
nothing calls this directly
no test coverage detected