Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Delay folder upload until all children files are parsed #559

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions src/traverseFileTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,32 @@ interface InternalDataTransferItem extends DataTransferItem {
path: string;
}

function loopFiles(item: InternalDataTransferItem, callback) {
const dirReader = item.createReader();
let fileList = [];

function sequence() {
dirReader.readEntries((entries: InternalDataTransferItem[]) => {
const entryList = Array.prototype.slice.apply(entries);
fileList = fileList.concat(entryList);
const traverseFileTree = (files: InternalDataTransferItem[], callback, isAccepted) => {
let restDirectory = 0;
const flattenFileList = [];
function loopFiles(item: InternalDataTransferItem, callback) {
const dirReader = item.createReader();
let fileList = [];

// Check if all the file has been viewed
const isFinished = !entryList.length;
function sequence() {
dirReader.readEntries((entries: InternalDataTransferItem[]) => {
const entryList = Array.prototype.slice.apply(entries);
fileList = fileList.concat(entryList);

if (isFinished) {
callback(fileList);
} else {
sequence();
}
});
}
// Check if all the file has been viewed
const isFinished = !entryList.length;

sequence();
}
if (isFinished) {
restDirectory--;
callback(fileList);
} else {
sequence();
}
});
}

const traverseFileTree = (files: InternalDataTransferItem[], callback, isAccepted) => {
sequence();
}
// eslint-disable-next-line @typescript-eslint/naming-convention
const _traverseFileTree = (item: InternalDataTransferItem, path?: string) => {
if (!item) {
Expand All @@ -59,10 +61,15 @@ const traverseFileTree = (files: InternalDataTransferItem[], callback, isAccepte
},
});
}
callback([file]);
flattenFileList.push(file);
console.log(restDirectory);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不应该有这个。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

马上马上

if (restDirectory === 0) {
callback(flattenFileList);
}
}
});
} else if (item.isDirectory) {
restDirectory++;
loopFiles(item, (entries: InternalDataTransferItem[]) => {
entries.forEach(entryItem => {
_traverseFileTree(entryItem, `${path}${item.name}/`);
Expand Down
Loading