From a2faaaca971c9cd6efa35ca5a769e7b60b6b5647 Mon Sep 17 00:00:00 2001 From: Glenn Van De Putte Date: Wed, 29 May 2024 14:23:02 +0200 Subject: [PATCH] fix: resolve and log warning when a subdirectory is dropped --- ember-file-upload/src/system/data-transfer-wrapper.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ember-file-upload/src/system/data-transfer-wrapper.ts b/ember-file-upload/src/system/data-transfer-wrapper.ts index 2140e6446..42eae7bed 100644 --- a/ember-file-upload/src/system/data-transfer-wrapper.ts +++ b/ember-file-upload/src/system/data-transfer-wrapper.ts @@ -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 => { +const readEntry = (entry: FileSystemEntry): Promise => { 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(); } }); }; @@ -41,8 +44,10 @@ const readAllFilesInDirectory = (item: DataTransferItem): Promise => } 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; }, );