@@ -106,8 +106,10 @@ export class UUIFileDropzoneElement extends LabelMixin('', LitElement) {
106
106
return ! dtItem . type ? dtItem . webkitGetAsEntry ( ) . isDirectory : false ;
107
107
}
108
108
109
- private async _getAllFileEntries ( dataTransferItemList : DataTransferItemList ) {
110
- const fileEntries : FileSystemFileEntry [ ] = [ ] ;
109
+ private async _getAllFileEntries (
110
+ dataTransferItemList : DataTransferItemList
111
+ ) : Promise < File [ ] > {
112
+ const fileEntries : File [ ] = [ ] ;
111
113
// Use BFS to traverse entire directory/file structure
112
114
const queue = [ ] ;
113
115
for ( let i = 0 ; i < dataTransferItemList . length ; i ++ ) {
@@ -129,35 +131,20 @@ export class UUIFileDropzoneElement extends LabelMixin('', LitElement) {
129
131
} ) ;
130
132
}
131
133
132
- while ( queue . length > 0 ) {
133
- const entry : FileSystemFileEntry = queue . shift ( ) ! ;
134
- if (
135
- entry . isFile &&
136
- ( await this . _isAccepted ( acceptList , wildcards , entry ) )
137
- ) {
138
- fileEntries . push ( entry ) ;
139
- } else if ( entry . isDirectory ) {
140
- fileEntries . push ( entry ) ;
141
- queue . push (
142
- ...( await this . _readAllDirectoryEntries (
143
- ( entry as any ) . createReader ( )
144
- ) )
145
- ) ;
146
- }
147
- }
148
- } else {
149
- while ( queue . length > 0 ) {
150
- const entry : FileSystemFileEntry = queue . shift ( ) ! ;
151
- if ( entry . isFile ) {
152
- fileEntries . push ( entry ) ;
153
- } else if ( entry . isDirectory ) {
154
- fileEntries . push ( entry ) ;
155
- queue . push (
156
- ...( await this . _readAllDirectoryEntries (
157
- ( entry as any ) . createReader ( )
158
- ) )
159
- ) ;
134
+ while ( queue . length > 0 ) {
135
+ const entry = queue . shift ( ) ! ;
136
+
137
+ if ( entry . kind === 'file' ) {
138
+ const file = entry . getAsFile ( ) ;
139
+ if ( ! file ) continue ;
140
+ if ( this . _isAccepted ( acceptList , wildcards , file ) ) {
141
+ fileEntries . push ( file ) ;
160
142
}
143
+ } else if ( entry . kind === 'directory' ) {
144
+ const directory = entry . webkitGetAsEntry ( ) ! as FileSystemDirectoryEntry ;
145
+ queue . push (
146
+ ...( await this . _readAllDirectoryEntries ( directory . createReader ( ) ) )
147
+ ) ;
161
148
}
162
149
}
163
150
0 commit comments