mirror of
https://github.com/HeyPuter/puter.git
synced 2025-01-26 17:28:47 +08:00
added Promises to handle multiple file creation and closing progress dialog
This commit is contained in:
parent
a09dd29416
commit
f0f8e454f9
@ -2196,16 +2196,33 @@ window.unzipItem = async function(itemPath) {
|
|||||||
}, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts)));
|
}, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts)));
|
||||||
} else {
|
} else {
|
||||||
const rootdir = await puter.fs.mkdir(path.dirname(filePath) + '/' + path.basename(filePath, '.zip'), { dedupeName: true });
|
const rootdir = await puter.fs.mkdir(path.dirname(filePath) + '/' + path.basename(filePath, '.zip'), { dedupeName: true });
|
||||||
Object.keys(unzipped).forEach(async (fileItem) => {
|
let queuedFileWrites = []
|
||||||
|
Object.keys(unzipped).forEach(fileItem => {
|
||||||
|
let fileWriteProcess = new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
let dirLevel, fileName;
|
let dirLevel, fileName;
|
||||||
let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]);
|
let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]);
|
||||||
if (fileItem.includes("/")) {
|
if (fileItem.includes("/")) {
|
||||||
[dirLevel, fileName] = [fileItem.slice(0, fileItem.lastIndexOf("/")), fileItem.slice(fileItem.lastIndexOf("/") + 1)]
|
[dirLevel, fileName] = [fileItem.slice(0, fileItem.lastIndexOf("/")), fileItem.slice(fileItem.lastIndexOf("/") + 1)]
|
||||||
await puter.fs.mkdir(rootdir.path + '/' + dirLevel, { createMissingParents: true });
|
// await puter.fs.mkdir(rootdir.path + '/' + dirLevel, { createMissingParents: true });
|
||||||
} else {
|
} else {
|
||||||
fileName = fileItem;
|
fileName = fileItem;
|
||||||
}
|
}
|
||||||
fileName != "" && await puter.fs.write(rootdir.path + '/' + fileItem, fileData);
|
fileName != "" && await puter.fs.write(rootdir.path + '/' + fileItem, fileData);
|
||||||
|
resolve();
|
||||||
|
} catch (e) {
|
||||||
|
UIAlert(e.message);
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
queuedFileWrites.push(fileWriteProcess);
|
||||||
|
});
|
||||||
|
Promise.all(queuedFileWrites).then(() => {
|
||||||
|
// close progress window
|
||||||
|
clearTimeout(progwin_timeout);
|
||||||
|
setTimeout(() => {
|
||||||
|
progwin?.close();
|
||||||
|
}, Math.max(0, window.unzip_progress_hide_delay - (Date.now() - start_ts)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user