@@ -61,10 +61,25 @@ const isDirectoryEntry = (entry: FileSystemEntry): entry is FileSystemDirectoryE
6161
6262const convertEntryToFile = ( entry : FileSystemFileEntry ) : Promise < File > =>
6363 new Promise ( ( resolve , reject ) => {
64- entry . file ( resolve , reject )
64+ entry . file ( file => {
65+ const cleanPath = entry . fullPath ?. startsWith ( '/' ) ? entry . fullPath . slice ( 1 ) : entry . fullPath
66+
67+ // If cleanPath === file.name => the file was NOT dropped from a folder, so we don't need to correct the webkitRelativePath
68+ // If cleanPath === file.webkitRelativePath => no issue in webkitRelativePath so no need to correct it
69+ if ( cleanPath !== file . webkitRelativePath && cleanPath !== file . name ) {
70+ Object . defineProperty ( file , 'webkitRelativePath' , {
71+ value : cleanPath ,
72+ writable : true ,
73+ enumerable : true ,
74+ configurable : true ,
75+ } )
76+ }
77+
78+ resolve ( file )
79+ } , reject )
6580 } )
6681
67- async function readEntriesInDirectory ( directory : FileSystemDirectoryEntry ) {
82+ const readEntriesInDirectory = async ( directory : FileSystemDirectoryEntry ) => {
6883 const reader = directory . createReader ( )
6984 const nestedEntries = [ ]
7085
@@ -82,8 +97,9 @@ async function readEntriesInDirectory(directory: FileSystemDirectoryEntry) {
8297/**
8398 * Recursive function to read all the files in a list of FileSystemEntry objects (files or directories)
8499 */
85- async function readEntries ( entries : FileSystemEntry [ ] ) : Promise < File [ ] > {
100+ const readEntries = async ( entries : FileSystemEntry [ ] ) : Promise < File [ ] > = > {
86101 const readFilesPromises = entries . filter ( entry => isFileEntry ( entry ) ) . map ( entry => convertEntryToFile ( entry ) )
102+
87103 const files = await Promise . all ( readFilesPromises )
88104
89105 const readFoldersPromises = entries
0 commit comments