Skip to content

Commit

Permalink
@uppy/utils: better fallbacks for the drag & drop API (#4260)
Browse files Browse the repository at this point in the history
@uppy/utils: be more defensive when falling back to the old API on drag&drop
  • Loading branch information
aduh95 committed Jan 26, 2023
1 parent 9d4d219 commit 79bab48
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}

0 comments on commit 79bab48

Please sign in to comment.