File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { useCallback , useMemo , useState } from 'react' ;
22import { read } from 'nmr-load-save' ;
3- import { fileCollectionFromFiles } from 'filelist-utils' ;
43import { Spectrum } from 'nmr-load-save/lib/types/Spectra/Spectrum' ;
54import events from '../events' ;
65import { isArrayOfString } from '../utilities/isArrayOfString' ;
76import { loadFilesFromURLs } from '../utilities/loadFilesFromURLs' ;
7+ import { createFileCollectionFromFiles } from '../utilities/createFileCollection' ;
88
99export function useLoadSpectra ( ) {
1010 const [ data , setData ] = useState < {
@@ -28,9 +28,8 @@ export function useLoadSpectra() {
2828 } else if ( 'files' in options ) {
2929 inputFiles = options . files ;
3030 }
31- const fileCollection = await fileCollectionFromFiles ( inputFiles , {
32- ignoreDotfiles : false ,
33- } ) ;
31+ // TODO use the new function from filelist-utils once they solve the problem of create filesCollection from files with empty webkitrelativepath
32+ const fileCollection = await createFileCollectionFromFiles ( inputFiles ) ;
3433 const { spectra, molecules } = await read ( fileCollection ) ;
3534 setData ( { spectra, molecules } ) ;
3635 } catch ( error : any ) {
Original file line number Diff line number Diff line change 1+ import { FileCollection , FileCollectionItem } from 'filelist-utils' ;
2+ import {
3+ maybeFilter ,
4+ FilterOptions ,
5+ } from 'filelist-utils/lib/utilities/maybeFilter' ;
6+ import { maybeExpand } from 'filelist-utils/lib/utilities/maybeExpand' ;
7+ import { ExpandOptions } from 'filelist-utils/lib/ExpandOptions' ;
8+
9+ export async function createFileCollectionFromFiles (
10+ files : File [ ] ,
11+ options : FilterOptions & ExpandOptions = { } ,
12+ ) {
13+ let fileCollections : FileCollectionItem [ ] = [ ] ;
14+
15+ // eslint-disable-next-line no-restricted-syntax
16+ for ( const file of files ) {
17+ const data : FileCollectionItem = {
18+ name : file . name ,
19+ size : file . size ,
20+ arrayBuffer : ( ) => file . arrayBuffer ( ) ,
21+ relativePath : file . webkitRelativePath || file . name ,
22+ lastModified : Date . now ( ) ,
23+ stream : ( ) => file . stream ( ) ,
24+ text : ( ) => file . text ( ) ,
25+ } ;
26+
27+ fileCollections . push ( data ) ;
28+ }
29+
30+ fileCollections = await maybeExpand ( fileCollections , options ) ;
31+ fileCollections = await maybeFilter ( fileCollections , options ) ;
32+
33+ return new FileCollection ( fileCollections ) ;
34+ }
You can’t perform that action at this time.
0 commit comments