mirror of
https://github.com/GSManagerXZ/GameServerManager.git
synced 2026-06-08 08:54:36 +08:00
文件管理异步修复
This commit is contained in:
@@ -515,8 +515,8 @@ const FileManagerPage: React.FC = () => {
|
||||
if (success) {
|
||||
addNotification({
|
||||
type: 'success',
|
||||
title: '压缩成功',
|
||||
message: `成功创建压缩文件 "${archiveName}"`
|
||||
title: '压缩任务已下发',
|
||||
message: `异步操作,详细进度可查看任务栏 "${archiveName}"`
|
||||
})
|
||||
}
|
||||
setCompressDialog({ visible: false, files: [] })
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user