mirror of
https://github.com/HeyPuter/puter
synced 2024-11-15 06:15:47 +00:00
offloaded write operations to Upload module
This commit is contained in:
parent
f32b1cfce8
commit
4fdea7db66
@ -2203,39 +2203,35 @@ 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 });
|
||||||
let queuedFileWrites = []
|
|
||||||
let perItemProgress = window.zippingProgressConfig.WRITING / Object.keys(unzipped).length;
|
let perItemProgress = window.zippingProgressConfig.WRITING / Object.keys(unzipped).length;
|
||||||
|
let queuedFileWrites = []
|
||||||
Object.keys(unzipped).forEach(fileItem => {
|
Object.keys(unzipped).forEach(fileItem => {
|
||||||
let fileWriteProcess = new Promise(async (resolve, reject) => {
|
try {
|
||||||
try {
|
let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]);
|
||||||
let dirLevel, fileName;
|
progwin?.set_status(i18n('writing', fileItem));
|
||||||
let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]);
|
queuedFileWrites.push(new File([fileData], fileItem))
|
||||||
if (fileItem.includes("/")) {
|
currentProgress += perItemProgress;
|
||||||
[dirLevel, fileName] = [fileItem.slice(0, fileItem.lastIndexOf("/")), fileItem.slice(fileItem.lastIndexOf("/") + 1)]
|
progwin?.set_progress(currentProgress.toPrecision(2));
|
||||||
await puter.fs.mkdir(rootdir.path + '/' + dirLevel, { createMissingParents: true });
|
} catch (e) {
|
||||||
} else {
|
UIAlert(e.message);
|
||||||
fileName = fileItem;
|
}
|
||||||
}
|
|
||||||
progwin?.set_status(i18n('writing', fileItem));
|
|
||||||
fileName != "" && await puter.fs.write(rootdir.path + '/' + fileItem, fileData);
|
|
||||||
currentProgress += perItemProgress;
|
|
||||||
progwin?.set_progress(currentProgress.toPrecision(2));
|
|
||||||
resolve();
|
|
||||||
} catch (e) {
|
|
||||||
UIAlert(e.message);
|
|
||||||
reject();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
queuedFileWrites.push(fileWriteProcess);
|
|
||||||
});
|
|
||||||
Promise.all(queuedFileWrites).then(() => {
|
|
||||||
progwin?.set_progress(window.zippingProgressConfig.TOTAL.toPrecision(2));
|
|
||||||
// close progress window
|
|
||||||
clearTimeout(progwin_timeout);
|
|
||||||
setTimeout(() => {
|
|
||||||
progwin?.close();
|
|
||||||
}, Math.max(0, window.unzip_progress_hide_delay - (Date.now() - start_ts)));
|
|
||||||
});
|
});
|
||||||
|
queuedFileWrites.length && puter.fs.upload(
|
||||||
|
// what to upload
|
||||||
|
queuedFileWrites,
|
||||||
|
// where to upload
|
||||||
|
rootdir.path + '/',
|
||||||
|
// options
|
||||||
|
{
|
||||||
|
createFileParent: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
progwin?.set_progress(window.zippingProgressConfig.TOTAL.toPrecision(2));
|
||||||
|
// 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