MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / importFilesFromPaths

Function importFilesFromPaths

src/stores/session.ts:316–478  ·  view source on GitHub ↗

* 批量导入多个文件(串行执行)

(filePaths: string[])

Source from the content-addressed store, hash-verified

314 * 批量导入多个文件(串行执行)
315 */
316 async function importFilesFromPaths(filePaths: string[]): Promise<BatchImportResult> {
317 if (filePaths.length === 0) {
318 return { total: 0, success: 0, failed: 0, cancelled: 0, files: [] }
319 }
320
321 // 初始化批量导入状态
322 isBatchImporting.value = true
323 batchImportCancelled.value = false
324 batchImportResult.value = null
325
326 // 初始化文件列表
327 batchFiles.value = filePaths.map((path) => ({
328 path,
329 name: path.split('/').pop() || path.split('\\').pop() || path,
330 status: 'pending' as BatchFileStatus,
331 }))
332
333 let successCount = 0
334 let failedCount = 0
335 let cancelledCount = 0
336
337 // 辅助函数:标记剩余文件为已取消
338 const markRemainingAsCancelled = (startIndex: number) => {
339 for (let j = startIndex; j < batchFiles.value.length; j++) {
340 if (batchFiles.value[j].status === 'pending') {
341 batchFiles.value[j].status = 'cancelled'
342 cancelledCount++
343 }
344 }
345 }
346
347 // 串行导入每个文件
348 for (let i = 0; i < batchFiles.value.length; i++) {
349 // 检查是否已取消
350 if (batchImportCancelled.value) {
351 markRemainingAsCancelled(i)
352 break
353 }
354
355 const file = batchFiles.value[i]
356 file.status = 'importing'
357 file.progress = {
358 stage: 'detecting',
359 progress: 0,
360 message: '',
361 }
362
363 try {
364 // 进度队列控制(复用单文件导入的逻辑)
365 const queue: ImportProgress[] = []
366 let isProcessing = false
367 let currentStage = 'reading'
368 let lastStageTime = Date.now()
369 const MIN_STAGE_TIME = 300 // 批量导入时缩短阶段显示时间
370
371 const processQueue = async () => {
372 if (isProcessing) return
373 isProcessing = true

Callers

nothing calls this directly

Calls 12

useImportServiceFunction · 0.90
useSessionIndexServiceFunction · 0.90
getSessionGapThresholdFunction · 0.90
markRemainingAsCancelledFunction · 0.85
processQueueFunction · 0.85
setTimeoutFunction · 0.85
loadSessionsFunction · 0.85
importFileMethod · 0.65
generateMethod · 0.65
errorMethod · 0.65
nowMethod · 0.45

Tested by

no test coverage detected