feat(remote): 实现文件上传真实进度显示
- 使用分块上传替代一次性上传 - 调用 /upload/start → /upload/chunk → /upload/merge 接口 - 通过 IPC 事件实时推送上传进度到前端 - 修复 merge 时未使用目标路径的问题
This commit is contained in:
@@ -102,11 +102,28 @@ export const uploadFileToRemote = async (
|
||||
password?: string,
|
||||
onProgress?: (progress: number) => void
|
||||
): Promise<void> => {
|
||||
onProgress?.(50)
|
||||
const result = await window.electronAPI.remoteUploadFile(serverHost, port, filePath, remotePath, password)
|
||||
onProgress?.(100)
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Upload failed')
|
||||
const transferId = Date.now().toString()
|
||||
|
||||
const cleanup = window.electronAPI?.onUploadProgress?.((data) => {
|
||||
if (data.id === transferId) {
|
||||
onProgress?.(data.progress)
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await window.electronAPI.remoteUploadFile(
|
||||
transferId,
|
||||
serverHost,
|
||||
port,
|
||||
filePath,
|
||||
remotePath,
|
||||
password
|
||||
)
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Upload failed')
|
||||
}
|
||||
} finally {
|
||||
cleanup?.()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
3
src/types/electron.d.ts
vendored
3
src/types/electron.d.ts
vendored
@@ -15,6 +15,7 @@ export interface ElectronAPI {
|
||||
onRemoteClipboardSyncFromRemote: (callback: () => void) => () => void
|
||||
onRemoteClipboardAutoSync: (callback: (text: string) => void) => () => void
|
||||
onDownloadProgress: (callback: (data: { progress: number; id: string }) => void) => () => void
|
||||
onUploadProgress: (callback: (data: { progress: number; id: string }) => void) => () => void
|
||||
clipboardReadText: () => Promise<{ success: boolean; text?: string; error?: string }>
|
||||
clipboardWriteText: (text: string) => Promise<{ success: boolean; error?: string }>
|
||||
remoteFetchDrives: (serverHost: string, port: number, password?: string) => Promise<{
|
||||
@@ -27,7 +28,7 @@ export interface ElectronAPI {
|
||||
data?: Array<{ name: string; path: string; type: 'file' | 'dir'; size: number; modified?: string }>
|
||||
error?: string
|
||||
}>
|
||||
remoteUploadFile: (serverHost: string, port: number, filePath: string, remotePath: string, password?: string) => Promise<{
|
||||
remoteUploadFile: (id: string, serverHost: string, port: number, filePath: string, remotePath: string, password?: string) => Promise<{
|
||||
success: boolean
|
||||
error?: string
|
||||
}>
|
||||
|
||||
Reference in New Issue
Block a user