feat(remote): 实现文件上传真实进度显示
- 使用分块上传替代一次性上传 - 调用 /upload/start → /upload/chunk → /upload/merge 接口 - 通过 IPC 事件实时推送上传进度到前端 - 修复 merge 时未使用目标路径的问题
This commit is contained in:
@@ -157,13 +157,13 @@ router.post('/upload/chunk', upload.single('chunk'), (req, res) => {
|
||||
|
||||
router.post('/upload/merge', (req, res) => {
|
||||
try {
|
||||
const { fileId, totalChunks, filename } = req.body;
|
||||
const { fileId, totalChunks, filename, path: targetPath } = req.body;
|
||||
|
||||
if (!fileId || !totalChunks || !filename) {
|
||||
return res.status(400).json({ error: 'Missing required fields' });
|
||||
}
|
||||
|
||||
const success = fileService.mergeChunks(fileId, parseInt(totalChunks), filename);
|
||||
const success = fileService.mergeChunks(fileId, parseInt(totalChunks), filename, targetPath);
|
||||
|
||||
if (success) {
|
||||
res.json({ success: true, filename });
|
||||
|
||||
@@ -91,9 +91,13 @@ class FileService {
|
||||
}
|
||||
}
|
||||
|
||||
mergeChunks(fileId, totalChunks, filename) {
|
||||
mergeChunks(fileId, totalChunks, filename, targetPath) {
|
||||
try {
|
||||
const filePath = path.normalize(filename);
|
||||
let targetDir = targetPath || 'C:\\';
|
||||
if (!fs.existsSync(targetDir)) {
|
||||
fs.mkdirSync(targetDir, { recursive: true });
|
||||
}
|
||||
const filePath = path.join(targetDir, filename);
|
||||
const dir = path.dirname(filePath);
|
||||
|
||||
if (!fs.existsSync(dir)) {
|
||||
|
||||
Reference in New Issue
Block a user