feat(remote): 添加 CORS 中间件支持文件跨域访问
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react'
|
||||
import { Folder, FileText, ChevronLeft, RefreshCw } from 'lucide-react'
|
||||
import { Folder, FileText, ChevronLeft, RefreshCw, HardDrive } from 'lucide-react'
|
||||
import { clsx } from 'clsx'
|
||||
import type { FileItem } from '@/lib/api'
|
||||
import { fetchSystemFiles } from '../../api'
|
||||
import { fetchSystemFiles, fetchSystemDrives } from '../../api'
|
||||
|
||||
interface LocalFilePanelProps {
|
||||
selectedFile: FileItem | null
|
||||
@@ -21,6 +21,7 @@ export const LocalFilePanel: React.FC<LocalFilePanelProps> = ({
|
||||
const [files, setFiles] = useState<FileItem[]>([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [pathHistory, setPathHistory] = useState<string[]>([''])
|
||||
const [isAtDrives, setIsAtDrives] = useState(true)
|
||||
|
||||
const loadFiles = useCallback(async (systemPath: string) => {
|
||||
setLoading(true)
|
||||
@@ -34,9 +35,25 @@ export const LocalFilePanel: React.FC<LocalFilePanelProps> = ({
|
||||
}
|
||||
}, [])
|
||||
|
||||
const loadDrives = useCallback(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const items = await fetchSystemDrives()
|
||||
setFiles(items)
|
||||
} catch (err) {
|
||||
console.error('Failed to load drives:', err)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
loadFiles(currentPath)
|
||||
}, [currentPath, loadFiles])
|
||||
if (isAtDrives) {
|
||||
loadDrives()
|
||||
} else {
|
||||
loadFiles(currentPath)
|
||||
}
|
||||
}, [currentPath, isAtDrives, loadFiles, loadDrives])
|
||||
|
||||
const handleGoBack = () => {
|
||||
if (pathHistory.length > 1) {
|
||||
@@ -45,23 +62,30 @@ export const LocalFilePanel: React.FC<LocalFilePanelProps> = ({
|
||||
const prevPath = newHistory[newHistory.length - 1]
|
||||
setPathHistory(newHistory)
|
||||
setCurrentPath(prevPath)
|
||||
if (prevPath === '') {
|
||||
setIsAtDrives(true)
|
||||
}
|
||||
onSelect(null)
|
||||
}
|
||||
}
|
||||
|
||||
const handleGoInto = (file: FileItem) => {
|
||||
setIsAtDrives(false)
|
||||
setPathHistory([...pathHistory, file.path])
|
||||
setCurrentPath(file.path)
|
||||
onSelect(null)
|
||||
}
|
||||
|
||||
const handleRefresh = () => {
|
||||
loadFiles(currentPath)
|
||||
if (isAtDrives) {
|
||||
loadDrives()
|
||||
} else {
|
||||
loadFiles(currentPath)
|
||||
}
|
||||
}
|
||||
|
||||
const getDisplayPath = () => {
|
||||
if (!currentPath) return '本地文件'
|
||||
if (currentPath === '' || currentPath === '/') return '根目录'
|
||||
if (isAtDrives) return '本地磁盘'
|
||||
const parts = currentPath.split(/[/\\]/)
|
||||
return parts[parts.length - 1] || currentPath
|
||||
}
|
||||
@@ -119,8 +143,12 @@ export const LocalFilePanel: React.FC<LocalFilePanelProps> = ({
|
||||
: 'hover:bg-gray-100 dark:hover:bg-gray-700/50 text-gray-700 dark:text-gray-200'
|
||||
)}
|
||||
>
|
||||
{file.type === 'dir' ? (
|
||||
<Folder size={16} className="text-gray-500 dark:text-gray-400 shrink-0" />
|
||||
{file.type === 'dir' || file.path.match(/^[A-Z]:\\?$/i) ? (
|
||||
file.path.match(/^[A-Z]:\\?$/i) ? (
|
||||
<HardDrive size={16} className="text-blue-500 dark:text-blue-400 shrink-0" />
|
||||
) : (
|
||||
<Folder size={16} className="text-gray-500 dark:text-gray-400 shrink-0" />
|
||||
)
|
||||
) : (
|
||||
<FileText size={16} className="text-gray-500 dark:text-gray-400 shrink-0" />
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user