Skip to content

Commit

Permalink
Filter out null file entries
Browse files Browse the repository at this point in the history
We have this entry null test elsewhere but were missing it while finding
the root entries in the drop transfer.

> If the item isn't a file, null is returned.
—https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry
  • Loading branch information
dgraham committed Mar 31, 2020
1 parent a62bce8 commit 35be7e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"plugin:github/es6",
"plugin:github/typescript"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
},
"globals": {
"FileAttachmentElement": "readable"
},
Expand Down
8 changes: 3 additions & 5 deletions src/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,8 @@ async function traverse(path: string, entries: FileSystemEntry[]): Promise<Attac
const results = []
for (const entry of visible(entries)) {
if (entry.isDirectory) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
results.push(...(await traverse(entry.fullPath, await getEntries(entry as any))))
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const file = await getFile(entry as any)
results.push(new Attachment(file, path))
}
Expand All @@ -150,7 +148,6 @@ async function traverse(path: string, entries: FileSystemEntry[]): Promise<Attac
function isDirectory(transfer: DataTransfer): boolean {
return (
transfer.items &&
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Array.from(transfer.items).some((item: any) => {
const entry = item.webkitGetAsEntry && item.webkitGetAsEntry()
return entry && entry.isDirectory
Expand All @@ -159,6 +156,7 @@ function isDirectory(transfer: DataTransfer): boolean {
}

function roots(transfer: DataTransfer): FileSystemEntry[] {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return Array.from(transfer.items).map((item: any) => item.webkitGetAsEntry())
return Array.from(transfer.items)
.map((item: any) => item.webkitGetAsEntry())
.filter(entry => entry != null)
}

0 comments on commit 35be7e0

Please sign in to comment.