From f9aaa3d4a220da3cd457ab6d9179f6a289d22bfd Mon Sep 17 00:00:00 2001 From: Jorylee <1747358809@qq.com> Date: Sun, 2 Feb 2025 00:25:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(file):=20=E4=BF=AE=E5=A4=8Dvfs=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=97=B6=E4=B8=A2=E5=A4=B1await=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 dealPngFileDrop 函数中添加 async/await 以确保文件写入操作是异步执行的 - 在 readClipboardItems 函数中添加 await 以确保文件写入操作完成后再继续执行后续代码 --- .../controlService/controller/concrete/ControllerDragFile.tsx | 4 ++-- src/core/service/dataManageService/copyEngine/copyEngine.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/service/controlService/controller/concrete/ControllerDragFile.tsx b/src/core/service/controlService/controller/concrete/ControllerDragFile.tsx index cc533265..e978d2bb 100644 --- a/src/core/service/controlService/controller/concrete/ControllerDragFile.tsx +++ b/src/core/service/controlService/controller/concrete/ControllerDragFile.tsx @@ -155,7 +155,7 @@ function dealJsonFileDrop(file: File, mouseWorldLocation: Vector) { function dealPngFileDrop(file: File, mouseWorldLocation: Vector) { const reader = new FileReader(); reader.readAsDataURL(file); // 以文本格式读取文件内容 - reader.onload = (e) => { + reader.onload = async (e) => { const fileContent = e.target?.result; // 读取的文件内容 if (typeof fileContent !== "string") { @@ -168,7 +168,7 @@ function dealPngFileDrop(file: File, mouseWorldLocation: Vector) { // data:image/png;base64,iVBORw0KGgoAAAANS... // 在这里处理读取到的内容 const imageUUID = uuidv4(); - VFileSystem.getFS().writeFileBase64(`/picture/${imageUUID}.png`, fileContent.split(",")[1]); + await VFileSystem.getFS().writeFileBase64(`/picture/${imageUUID}.png`, fileContent.split(",")[1]); const imageNode = new ImageNode({ uuid: imageUUID, location: [mouseWorldLocation.x, mouseWorldLocation.y], diff --git a/src/core/service/dataManageService/copyEngine/copyEngine.tsx b/src/core/service/dataManageService/copyEngine/copyEngine.tsx index 1e811e35..185f62e9 100644 --- a/src/core/service/dataManageService/copyEngine/copyEngine.tsx +++ b/src/core/service/dataManageService/copyEngine/copyEngine.tsx @@ -130,7 +130,7 @@ async function readClipboardItems(mouseLocation: Vector) { const blob = await item.getType(item.types[0]); // 获取 Blob 对象 const imageUUID = uuidv4(); //const folder = PathString.dirPath(Stage.path.getFilePath()); - VFileSystem.getFS().writeFile(`/picture/${imageUUID}.png`, await blob.bytes()); + await VFileSystem.getFS().writeFile(`/picture/${imageUUID}.png`, await blob.bytes()); //const imagePath = `${folder}${PathString.getSep()}${imageUUID}.png`; // 2024.12.31 测试发现这样的写法会导致读取时base64解码失败