Leverage existing iterator, don't reinvent wheel...

This commit is contained in:
Jaifroid 2023-10-26 15:19:24 +01:00
parent 635fbd64de
commit 35b87b90c8

View File

@ -921,31 +921,12 @@ function iterateAsyncDirEntries (entries, archives, noFilter) {
function iterateOPFSEntries () { function iterateOPFSEntries () {
if (navigator && navigator.storage && 'getDirectory' in navigator.storage) { if (navigator && navigator.storage && 'getDirectory' in navigator.storage) {
return navigator.storage.getDirectory().then(function (dirHandle) { return navigator.storage.getDirectory().then(function (dirHandle) {
var archiveEntries = [];
var entries = dirHandle.entries(); var entries = dirHandle.entries();
var promisesForEntries = []; return iterateAsyncDirEntries(entries, []).then(function (archiveList) {
// Push the pormise for each entry to the promises array return archiveList;
var pushPromises = new Promise(function (resolve) { }).catch(function (err) {
(function iterate () { console.error('Unable to iterate OPFS entries', err);
return entries.next().then(function (result) { throw err;
if (!result.done) {
// Process the entry, then continue iterating
var entry = result.value[1];
archiveEntries.push(entry);
promisesForEntries.push(result);
iterate();
} else {
return resolve(true);
}
});
})();
});
return pushPromises.then(function () {
return Promise.all(promisesForEntries).then(function () {
return archiveEntries;
}).catch(function (err) {
console.error('Unable to iterate OPFS entries', err);
});
}); });
}); });
} }