feat(remote): 实现文件上传真实进度显示

- 使用分块上传替代一次性上传
- 调用 /upload/start → /upload/chunk → /upload/merge 接口
- 通过 IPC 事件实时推送上传进度到前端
- 修复 merge 时未使用目标路径的问题
This commit is contained in:
2026-03-10 15:36:10 +08:00
parent 433db24688
commit de4c101b36
10 changed files with 142 additions and 42 deletions

View File

@@ -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?.()
}
}