Skip to content

Commit

Permalink
feat:improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
coderz-w committed Jul 11, 2024
1 parent b381da4 commit c151816
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/traverseFileTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ interface InternalDataTransferItem extends DataTransferItem {
const traverseFileTree = (files: InternalDataTransferItem[], callback, isAccepted) => {
const flattenFileList = [];
let progressFileList = [];
let wipIndex = 0;
files.forEach(file => progressFileList.push(file.webkitGetAsEntry() as any));
function loopFiles(item: InternalDataTransferItem) {
const dirReader = item.createReader();
let fileList = [];

function sequence() {
dirReader.readEntries((entries: InternalDataTransferItem[]) => {
const entryList = Array.prototype.slice.apply(entries);
fileList.push(...entryList);

progressFileList.push(...entryList);
// Check if all the file has been viewed
const isFinished = !entryList.length;

if (isFinished) {
progressFileList = progressFileList.concat(fileList);
return;
} else {
sequence();
}
Expand Down Expand Up @@ -71,6 +68,7 @@ const traverseFileTree = (files: InternalDataTransferItem[], callback, isAccepte
};

function walkFiles() {
let wipIndex = 0;
while (wipIndex < progressFileList.length) {
_traverseFileTree(progressFileList[wipIndex]);
wipIndex++;
Expand Down

0 comments on commit c151816

Please sign in to comment.