mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-08-03 19:38:36 -04:00
Leverage existing iterator, don't reinvent wheel...
This commit is contained in:
parent
635fbd64de
commit
35b87b90c8
@ -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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user