Skip to content

Commit

Permalink
fix(file): 修复vfs操作时丢失await的问题
Browse files Browse the repository at this point in the history
- 在 dealPngFileDrop 函数中添加 async/await 以确保文件写入操作是异步执行的
- 在 readClipboardItems 函数中添加 await 以确保文件写入操作完成后再继续执行后续代码
  • Loading branch information
neooier committed Feb 1, 2025
1 parent 9fec9be commit f9aaa3d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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解码失败
Expand Down

0 comments on commit f9aaa3d

Please sign in to comment.