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

Function importFileFromPath

src/stores/session.ts:223–311  ·  view source on GitHub ↗

* 从指定路径执行导入(支持拖拽)

(filePath: string)

Source from the content-addressed store, hash-verified

221 * 从指定路径执行导入(支持拖拽)
222 */
223 async function importFileFromPath(filePath: string): Promise<{
224 success: boolean
225 error?: string
226 diagnostics?: ImportDiagnosticsInfo
227 }> {
228 try {
229 isImporting.value = true
230 importProgress.value = {
231 stage: 'detecting',
232 progress: 0,
233 message: '',
234 }
235
236 const queue: ImportProgress[] = []
237 let isProcessing = false
238 let currentStage = 'reading'
239 let lastStageTime = Date.now()
240 const MIN_STAGE_TIME = 1000
241
242 const processQueue = async () => {
243 if (isProcessing) return
244 isProcessing = true
245
246 while (queue.length > 0) {
247 const next = queue[0]
248
249 if (next.stage !== currentStage) {
250 const elapsed = Date.now() - lastStageTime
251 if (elapsed < MIN_STAGE_TIME) {
252 await new Promise((resolve) => setTimeout(resolve, MIN_STAGE_TIME - elapsed))
253 }
254 currentStage = next.stage
255 lastStageTime = Date.now()
256 }
257
258 importProgress.value = queue.shift()!
259 }
260 isProcessing = false
261 }
262
263 const importResult = await useImportService().importFile(filePath, undefined, (progress) => {
264 if (progress.stage === 'done') return
265 queue.push(progress)
266 processQueue()
267 })
268
269 while (queue.length > 0 || isProcessing) {
270 await new Promise((resolve) => setTimeout(resolve, 100))
271 }
272
273 const elapsed = Date.now() - lastStageTime
274 if (elapsed < MIN_STAGE_TIME) {
275 await new Promise((resolve) => setTimeout(resolve, MIN_STAGE_TIME - elapsed))
276 }
277
278 if (importProgress.value) {
279 importProgress.value.progress = 100
280 }

Callers 1

importFileFunction · 0.85

Calls 11

useImportServiceFunction · 0.90
useSessionIndexServiceFunction · 0.90
getSessionGapThresholdFunction · 0.90
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