Skip to content

Commit

Permalink
fix: resolve and log warning when a subdirectory is dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
Glenn Van De Putte committed May 29, 2024
1 parent 8770ea8 commit a2faaac
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ember-file-upload/src/system/data-transfer-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ export interface FileWithDirectory {
const getDataSupport = {};

// this will read a filesystementry into a File object, but ignore the entry if it is a directory
const readEntry = (entry: FileSystemEntry): Promise<File> => {
const readEntry = (entry: FileSystemEntry): Promise<File | void> => {
return new Promise((resolve) => {
if (entry.isFile) {
(entry as FileSystemFileEntry).file((fileEntry: File) => {
resolve(fileEntry);
});
} else {
console.warn(`The dropped directory contains a subdirectory ${entry.fullPath}, the contents of this will be skipped.`);
resolve();
}
});
};
Expand All @@ -41,8 +44,10 @@ const readAllFilesInDirectory = (item: DataTransferItem): Promise<File[]> =>
}

entry?.createReader()?.readEntries(async (entries: FileSystemEntry[]) => {
const readFiles: File[] = await Promise.all(entries.map(readEntry)).catch(
const readFiles: (File | void)[] = await Promise.all(entries.map(readEntry))
.catch(
(err) => {
console.error(err)
throw err;
},
);
Expand Down

0 comments on commit a2faaac

Please sign in to comment.