Skip to content

Commit 90fa75c

Browse files
committed
chore: use async/await in fromDataTransferItem
1 parent 5ec58b2 commit 90fa75c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/file-selector.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,25 @@ function flatten<T>(items: any[]): T[] {
120120
], []);
121121
}
122122

123-
function fromDataTransferItem(item: DataTransferItem, entry?: FileSystemEntry | null) {
123+
async function fromDataTransferItem(item: DataTransferItem, entry?: FileSystemEntry | null) {
124124
// Check if we're in a secure context; due to a bug in Chrome (as far as we know)
125125
// the browser crashes when calling this API (yet to be confirmed as a consistent behaviour).
126126
//
127127
// See:
128128
// - https://issues.chromium.org/issues/40186242
129129
// - https://github.com/react-dropzone/react-dropzone/issues/1397
130130
if (globalThis.isSecureContext && typeof (item as any).getAsFileSystemHandle === 'function') {
131-
return (item as any).getAsFileSystemHandle()
132-
.then(async (h: any) => {
133-
const file = await h.getFile();
134-
file.handle = h;
135-
return toFileWithPath(file);
136-
});
131+
const h = await (item as any).getAsFileSystemHandle();
132+
const file = await h.getFile();
133+
file.handle = h;
134+
return toFileWithPath(file);
137135
}
138136
const file = item.getAsFile();
139137
if (!file) {
140-
return Promise.reject(`${item} is not a File`);
138+
throw new Error(`${item} is not a File`);
141139
}
142140
const fwp = toFileWithPath(file, entry?.fullPath ?? undefined);
143-
return Promise.resolve(fwp);
141+
return fwp;
144142
}
145143

146144
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry

0 commit comments

Comments
 (0)