Skip to content

Commit

Permalink
fix: missing files on traversing folder (close AlistGo/alist#5034)
Browse files Browse the repository at this point in the history
Caused by 43adecd
  • Loading branch information
xhofe committed Aug 19, 2023
1 parent 1450bb2 commit 0614866
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/pages/home/uploads/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,28 @@ export const traverseFileTree = async (entry: FileSystemEntry) => {
}, errorCallback)
} else if (entry.isDirectory) {
const dirReader = (entry as FileSystemDirectoryEntry).createReader()
dirReader.readEntries(async (entries) => {
for (let i = 0; i < entries.length; i++) {
await internalProcess(entries[i], path + entry.name + "/")
}
resolve({})
}, errorCallback)
const readEntries = () => {
dirReader.readEntries(async (entries) => {
for (let i = 0; i < entries.length; i++) {
await internalProcess(entries[i], path + entry.name + "/")
}
resolve({})
/**
why? https://stackoverflow.com/questions/3590058/does-html5-allow-drag-drop-upload-of-folders-or-a-folder-tree/53058574#53058574
Unfortunately none of the existing answers are completely correct because
readEntries will not necessarily return ALL the (file or directory) entries for a given directory.
This is part of the API specification (see Documentation section below).
To actually get all the files, we'll need to call readEntries repeatedly (for each directory we encounter)
until it returns an empty array. If we don't, we will miss some files/sub-directories in a directory
e.g. in Chrome, readEntries will only return at most 100 entries at a time.
*/
if (entries.length > 0) {
readEntries()
}
}, errorCallback)
}
readEntries()
}
})
await promise
Expand Down

0 comments on commit 0614866

Please sign in to comment.