MCPcopy Create free account
hub / github.com/codeHappyDananx/SpecWave / loadFile

Function loadFile

src/stores/project.ts:597–657  ·  view source on GitHub ↗
(filePath: string, options: { silent?: boolean } = {})

Source from the content-addressed store, hash-verified

595
596 // 读取文件内容
597 async function loadFile(filePath: string, options: { silent?: boolean } = {}): Promise<void> {
598 if (!projectPath.value || !isElectron()) return
599 const silent = options.silent === true
600
601 try {
602 if (!silent) {
603 isFileLoading.value = true
604 error.value = ''
605 }
606
607 const fullPath = `${projectPath.value}/${filePath}`
608 const result = await window.electronAPI!.readFile(fullPath)
609
610 if (result.success && result.content !== undefined) {
611 const fileName = filePath.split(/[/\\]/).pop() || ''
612 const isTask = fileName === 'tasks.md'
613 const isImage = result.isImage || false
614
615 let fileType: 'markdown' | 'task' | 'code' | 'text' | 'image' | 'other' = 'text'
616 if (isImage) {
617 fileType = 'image'
618 } else if (isTask) {
619 fileType = 'task'
620 } else if (fileName.endsWith('.md')) {
621 fileType = 'markdown'
622 } else if (result.fileType && ['javascript', 'typescript', 'vue', 'json', 'yaml', 'css', 'html', 'python', 'java', 'sql', 'text', 'bash', 'batch', 'powershell'].includes(result.fileType)) {
623 fileType = 'code'
624 }
625
626 currentFile.value = {
627 path: filePath,
628 name: fileName,
629 content: result.content,
630 type: fileType,
631 fileType: result.fileType,
632 isImage,
633 encoding: result.encoding,
634 bom: result.bom,
635 eol: result.eol
636 }
637
638 // 如果是任务文件,解析进度
639 if (isTask) {
640 const progress = parseTaskProgress(result.content)
641 updateNodeProgress(filePath, progress)
642 }
643 } else {
644 if (!silent) {
645 error.value = result.error || '读取文件失败'
646 }
647 }
648 } catch (err: any) {
649 if (!silent) {
650 error.value = err.message || '读取文件失败'
651 }
652 } finally {
653 if (!silent) {
654 isFileLoading.value = false

Callers 1

Calls 3

isElectronFunction · 0.85
parseTaskProgressFunction · 0.85
updateNodeProgressFunction · 0.85

Tested by

no test coverage detected