fix(remote): 上传下载现在使用文件面板当前选择的路径

This commit is contained in:
2026-03-09 19:48:15 +08:00
parent 4c18edf74f
commit 4273b3d43b
7 changed files with 35 additions and 145 deletions

View File

@@ -39,6 +39,7 @@ const createEmptyDevice = (): RemoteDevice => ({
serverHost: '',
desktopPort: 3000,
gitPort: 3001,
openCodePort: 3002,
})
export const RemotePage: React.FC = () => {
@@ -81,6 +82,13 @@ export const RemotePage: React.FC = () => {
try {
const savedConfig = await getRemoteConfig()
const configWithDevices = savedConfig.devices ? savedConfig : { devices: [] }
// 确保每个设备都有 openCodePort 默认值
configWithDevices.devices = configWithDevices.devices.map(device => ({
...device,
openCodePort: device.openCodePort || 3002,
desktopPort: device.desktopPort || 3000,
gitPort: device.gitPort || 3001,
}))
setConfig(configWithDevices)
if (configWithDevices.devices.length > 0 && !selectedDeviceId) {
setSelectedDeviceId(configWithDevices.devices[0].id)
@@ -209,12 +217,9 @@ export const RemotePage: React.FC = () => {
setShowConfig(true)
return
}
let url = `http://${selectedConfig.serverHost}:${selectedConfig.desktopPort}/opencode`
if (selectedConfig.password) {
url += `?password=${encodeURIComponent(selectedConfig.password)}`
}
let url = `http://${selectedConfig.serverHost}:${selectedConfig.openCodePort}`
const deviceName = selectedConfig.deviceName ? ` - ${selectedConfig.deviceName}` : ''
const fileItem = createRemoteDesktopFileItem(url, `OpenCode${deviceName}`, selectedConfig.deviceName)
const fileItem = createRemoteGitFileItem(url, `OpenCode${deviceName}`, selectedConfig.deviceName)
selectFile(fileItem)
}

View File

@@ -155,6 +155,19 @@ export const ConfigDialog: React.FC<ConfigDialogProps> = ({
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
OpenCode
</label>
<input
type="number"
value={formData.openCodePort}
onChange={(e) => handleChange('openCodePort', parseInt(e.target.value) || 3002)}
placeholder="默认: 3002"
className="w-full px-3 py-2 bg-gray-50 dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-gray-900 dark:focus:ring-gray-100 focus:border-transparent transition-colors"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
访

View File

@@ -16,6 +16,7 @@ interface FileTransferPageProps {
export const FileTransferPage: React.FC<FileTransferPageProps> = ({ serverHost, port, password, onClose }) => {
const [localSelected, setLocalSelected] = useState<FileItem | null>(null)
const [remoteSelected, setRemoteSelected] = useState<RemoteFileItem | null>(null)
const [remotePath, setRemotePath] = useState('')
const [transfers, setTransfers] = useState<TransferItem[]>([])
const [transferring, setTransferring] = useState(false)
const [transferQueueHeight, setTransferQueueHeight] = useState(128)
@@ -42,7 +43,7 @@ export const FileTransferPage: React.FC<FileTransferPageProps> = ({ serverHost,
const blob = await fetchSystemFileContent(localSelected.path)
const file = new File([blob], localSelected.name, { type: blob.type })
await uploadFileToRemote(serverHost, port, file, '', password, (progress) => {
await uploadFileToRemote(serverHost, port, file, remotePath, password, (progress) => {
setTransfers((prev) =>
prev.map((t) => (t.id === transferId ? { ...t, progress } : t))
)
@@ -84,7 +85,7 @@ export const FileTransferPage: React.FC<FileTransferPageProps> = ({ serverHost,
setTransfers((prev) => [...prev, newTransfer])
try {
await downloadFileFromRemote(serverHost, port, remoteSelected.name, '', password, (progress) => {
await downloadFileFromRemote(serverHost, port, remoteSelected.name, remotePath, password, (progress) => {
setTransfers((prev) =>
prev.map((t) => (t.id === transferId ? { ...t, progress } : t))
)
@@ -166,6 +167,7 @@ export const FileTransferPage: React.FC<FileTransferPageProps> = ({ serverHost,
selectedFile={remoteSelected}
onSelect={setRemoteSelected}
onDownload={handleDownload}
onPathChange={setRemotePath}
disabled={transferring}
/>
</div>

View File

@@ -10,6 +10,7 @@ interface RemoteFilePanelProps {
selectedFile: RemoteFileItem | null
onSelect: (file: RemoteFileItem | null) => void
onDownload: () => void
onPathChange?: (path: string) => void
disabled?: boolean
}
@@ -20,6 +21,7 @@ export const RemoteFilePanel: React.FC<RemoteFilePanelProps> = ({
selectedFile,
onSelect,
onDownload,
onPathChange,
disabled,
}) => {
const [currentPath, setCurrentPath] = useState('')
@@ -71,6 +73,7 @@ export const RemoteFilePanel: React.FC<RemoteFilePanelProps> = ({
setPathHistory(newHistory)
setCurrentPath(prevPath)
onSelect(null)
onPathChange?.(prevPath)
} else {
loadDrives()
}
@@ -82,11 +85,13 @@ export const RemoteFilePanel: React.FC<RemoteFilePanelProps> = ({
setPathHistory(['', newPath])
setCurrentPath(newPath)
loadFiles(newPath)
onPathChange?.(newPath)
} else {
const newPath = currentPath ? `${currentPath}\\${file.name}` : file.name
setPathHistory([...pathHistory, newPath])
setCurrentPath(newPath)
loadFiles(newPath)
onPathChange?.(newPath)
}
onSelect(null)
}
@@ -104,6 +109,7 @@ export const RemoteFilePanel: React.FC<RemoteFilePanelProps> = ({
setCurrentPath('')
loadDrives()
onSelect(null)
onPathChange?.('')
}
const getDisplayPath = () => {

View File

@@ -14,6 +14,7 @@ export interface RemoteDevice {
serverHost: string
desktopPort: number
gitPort: number
openCodePort: number
password?: string
}