import { IRoot } from '../../store/slices/storage/storage.thunks/uploadFolderThunk' ; interface FileSystemFileEntry extends FileSystemEntry { file : ( successCallback : ( file : File ) => void ) => void ; } param items params returns returns export async function transformDraggedItems ( items , topLevelPath ) { const topLevelFiles = [ ] ; const topLevelDirectories = [ ] ; for ( let i = 0 ; i < items . length ; i ++ ) { const item = items [ i ] ; const entry = item . webkitGetAsEntry ( ) ; if ( entry ) { if ( entry . isFile ) { topLevelFiles . push ( item . getAsFile ( ) as File ) ; } else { topLevelDirectories . push ( entry as FileSystemDirectoryEntry ) ; } } else { topLevelFiles . push ( item . getAsFile ( ) as File ) ; } } const rootList = await Promise . all ( topLevelDirectories . map ( ( directory ) => transformEntryToRoot ( directory , topLevelPath ) ) ) ; return { rootList , files : topLevelFiles } ; } async function transformEntryToRoot ( entry , currentPath ) { const entries = await getEntriesFromDirectory ( entry ) ; const fullPathEdited = `${ currentPath }/${ entry . name }` ; const childrenFilesPromises = Promise . all ( entries . filter ( ( entry ) => entry . isFile ) . map ( ( entry ) => getFileFromEntry ( entry as FileSystemFileEntry ) ) ) ; const childrenFoldersPromises = Promise . all ( entries . filter ( ( entry ) => entry . isDirectory ) . map ( ( entry ) => transformEntryToRoot ( entry as FileSystemDirectoryEntry , fullPathEdited ) ) ) ; const [ childrenFiles , childrenFolders ] = await Promise . all ( [ childrenFilesPromises , childrenFoldersPromises ] ) ; return { name : entry . name , childrenFiles , childrenFolders , folderId : null , fullPathEdited , } ; } function getEntriesFromDirectory ( entry ) { return new Promise ( ( resolve , reject ) => { entry . createReader ( ) . readEntries ( resolve , reject ) ; } ) ; } function getFileFromEntry ( entry ) { return new Promise ( ( resolve ) => { entry . file ( resolve ) ; } ) ; }