From e8b6b696c502aa3be6dc3a31b5eea230fa5d35ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9C=B1?= <10714957+xiao-zhu245@user.noreply.gitee.com> Date: Thu, 10 Jul 2025 22:27:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/pages/FileManagerPage.tsx | 4 +-- server/src/modules/task/compressionWorker.ts | 35 +++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/client/src/pages/FileManagerPage.tsx b/client/src/pages/FileManagerPage.tsx index 68e33a8..5e79f8b 100644 --- a/client/src/pages/FileManagerPage.tsx +++ b/client/src/pages/FileManagerPage.tsx @@ -515,8 +515,8 @@ const FileManagerPage: React.FC = () => { if (success) { addNotification({ type: 'success', - title: '压缩成功', - message: `成功创建压缩文件 "${archiveName}"` + title: '压缩任务已下发', + message: `异步操作,详细进度可查看任务栏 "${archiveName}"` }) } setCompressDialog({ visible: false, files: [] }) diff --git a/server/src/modules/task/compressionWorker.ts b/server/src/modules/task/compressionWorker.ts index 3eb87b9..7a31867 100644 --- a/server/src/modules/task/compressionWorker.ts +++ b/server/src/modules/task/compressionWorker.ts @@ -126,22 +126,39 @@ export class CompressionWorker { const stream = createReadStream(archivePath) .pipe(unzipper.Parse()) - stream.on('entry', (entry) => { + stream.on('entry', async (entry) => { totalFiles++ const fileName = entry.path const type = entry.type const filePath = path.join(targetPath, fileName) if (type === 'File') { - entry.pipe(createWriteStream(filePath)) - entry.on('close', () => { - extractedFiles++ - const progress = Math.floor((extractedFiles / totalFiles) * 90) + 5 - taskManager.updateTask(taskId, { - message: `正在解压... (${extractedFiles}/${totalFiles})`, - progress: Math.min(95, progress) + try { + // 确保文件所在的目录存在 + const fileDir = path.dirname(filePath) + await fs.mkdir(fileDir, { recursive: true }) + + entry.pipe(createWriteStream(filePath)) + entry.on('close', () => { + extractedFiles++ + const progress = Math.floor((extractedFiles / totalFiles) * 90) + 5 + taskManager.updateTask(taskId, { + message: `正在解压... (${extractedFiles}/${totalFiles})`, + progress: Math.min(95, progress) + }) }) - }) + } catch (error) { + console.error(`创建目录失败: ${path.dirname(filePath)}`, error) + entry.autodrain() + } + } else if (type === 'Directory') { + // 处理目录条目 + try { + await fs.mkdir(filePath, { recursive: true }) + } catch (error) { + console.error(`创建目录失败: ${filePath}`, error) + } + entry.autodrain() } else { entry.autodrain() }