From 79bab48dc15ab025a3f1d1edbc3d519e2675896f Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 26 Jan 2023 16:39:27 +0100 Subject: [PATCH] @uppy/utils: better fallbacks for the drag & drop API (#4260) @uppy/utils: be more defensive when falling back to the old API on drag&drop --- .../utils/webkitGetAsEntryApi/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/@uppy/utils/src/getDroppedFiles/utils/webkitGetAsEntryApi/index.js b/packages/@uppy/utils/src/getDroppedFiles/utils/webkitGetAsEntryApi/index.js index 31214ec439..9c1e539066 100644 --- a/packages/@uppy/utils/src/getDroppedFiles/utils/webkitGetAsEntryApi/index.js +++ b/packages/@uppy/utils/src/getDroppedFiles/utils/webkitGetAsEntryApi/index.js @@ -25,19 +25,19 @@ function getAsFileSystemHandleFromEntry (entry, logDropError) { } } -async function* createPromiseToAddFileOrParseDirectory (entry, relativePath) { +async function* createPromiseToAddFileOrParseDirectory (entry, relativePath, lastResortFile = undefined) { // For each dropped item, - make sure it's a file/directory, and start deepening in! if (entry.kind === 'file') { const file = await entry.getFile() if (file !== null) { file.relativePath = relativePath ? `${relativePath}/${entry.name}` : null yield file - } + } else if (lastResortFile != null) yield lastResortFile } else if (entry.kind === 'directory') { for await (const handle of entry.values()) { yield* createPromiseToAddFileOrParseDirectory(handle, `${relativePath}/${entry.name}`) } - } + } else if (lastResortFile != null) yield lastResortFile } export default async function* getFilesFromDataTransfer (dataTransfer, logDropError) { @@ -53,14 +53,14 @@ export default async function* getFilesFromDataTransfer (dataTransfer, logDropEr // :entry can be null when we drop the url e.g. if (entry != null) { try { - yield* createPromiseToAddFileOrParseDirectory(entry, '') + yield* createPromiseToAddFileOrParseDirectory(entry, '', lastResortFile) } catch (err) { - if (lastResortFile) { + if (lastResortFile != null) { yield lastResortFile } else { logDropError(err) } } - } + } else if (lastResortFile != null) yield lastResortFile } }