Skip to content

Commit 0df8e12

Browse files
committed
chore: use async/await in fromDataTransferItem
1 parent 2ad7fc2 commit 0df8e12

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/file-selector.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function flatten<T>(items: any[]): T[] {
105105
);
106106
}
107107

108-
function fromDataTransferItem(
108+
async function fromDataTransferItem(
109109
item: DataTransferItem,
110110
entry?: FileSystemEntry | null,
111111
) {
@@ -118,18 +118,17 @@ function fromDataTransferItem(
118118
globalThis.isSecureContext &&
119119
typeof (item as any).getAsFileSystemHandle === "function"
120120
) {
121-
return (item as any).getAsFileSystemHandle().then(async (h: any) => {
122-
const file = await h.getFile();
123-
file.handle = h;
124-
return toFileWithPath(file);
125-
});
121+
const h = await (item as any).getAsFileSystemHandle();
122+
const file = await h.getFile();
123+
file.handle = h;
124+
return toFileWithPath(file);
126125
}
127126
const file = item.getAsFile();
128127
if (!file) {
129-
return Promise.reject(`${item} is not a File`);
128+
throw new Error(`${item} is not a File`);
130129
}
131130
const fwp = toFileWithPath(file, entry?.fullPath ?? undefined);
132-
return Promise.resolve(fwp);
131+
return fwp;
133132
}
134133

135134
async function fromEntry(

0 commit comments

Comments
 (0)