@@ -268,7 +268,7 @@ export async function getDirectoryContents( path, dirHandle ) {
268268 else {
269269 // Web server
270270 const response = await fetch ( path ) ;
271- content = response . ok ? await response . text ( ) : false ;
271+ content = response . ok ? await response . json ( ) : false ;
272272 }
273273 }
274274 catch ( e ) {
@@ -365,58 +365,7 @@ export function parseWebIndex( content ) {
365365 */
366366export function parseDirectory ( content , path ) {
367367
368- // NOTE: `path` is currently used only to generate the correct `src` for subs files when
369- // reading an arbitrary directory. For all other files, only the filename is included.
370- //
371- // TO-DO: add an extra `path` or `src` property to *all* entries in the returned object,
372- // so we don't have to deal with this everywhere else!
373-
374- const coverExtensions = / \. ( j p g | j p e g | w e b p | a v i f | p n g | g i f | b m p ) $ / i,
375- subsExtensions = / \. v t t $ / i;
376-
377- let dirs = [ ] ,
378- files = [ ] ,
379- imgs = [ ] ,
380- subs = [ ] ;
381-
382- // helper function
383- const findImg = ( arr , pattern ) => {
384- const regexp = new RegExp ( `${ pattern } .*${ coverExtensions . source } ` , 'i' ) ;
385- return arr . find ( el => ( el . name || el ) . match ( regexp ) ) ;
386- }
387-
388- if ( Array . isArray ( content ) && supportsFileSystemAPI ) {
389- // File System entries
390- for ( const fileObj of content ) {
391- const { name, handle, dirHandle } = fileObj ;
392- if ( handle instanceof FileSystemDirectoryHandle )
393- dirs . push ( fileObj ) ;
394- else if ( handle instanceof FileSystemFileHandle ) {
395- if ( name . match ( coverExtensions ) )
396- imgs . push ( fileObj ) ;
397- else if ( name . match ( subsExtensions ) )
398- subs . push ( fileObj ) ;
399- if ( name . match ( fileExtensions ) )
400- files . push ( fileObj ) ;
401- }
402- }
403- }
404- else {
405- // Web server HTML content
406- for ( const { url, file } of parseWebIndex ( content ) ) {
407- const fileObj = { name : file } ;
408- if ( url . slice ( - 1 ) == '/' )
409- dirs . push ( fileObj ) ;
410- else {
411- if ( file . match ( coverExtensions ) )
412- imgs . push ( fileObj ) ;
413- else if ( file . match ( subsExtensions ) )
414- subs . push ( fileObj ) ;
415- if ( file . match ( fileExtensions ) )
416- files . push ( fileObj ) ;
417- }
418- }
419- }
368+ let { dirs, files, imgs, subs} = content ;
420369
421370 // attach subtitle entries to their respective media files
422371 for ( const sub of subs ) {
@@ -428,6 +377,12 @@ export function parseDirectory( content, path ) {
428377 fileEntry . subs = { src : path ? path + name : makePath ( name ) , lang, handle } ;
429378 }
430379
380+ // helper function
381+ const findImg = ( arr , pattern ) => {
382+ const regexp = new RegExp ( pattern , 'i' ) ;
383+ return arr . find ( el => ( el . name || el ) . match ( regexp ) ) ;
384+ } ;
385+
431386 const cover = findImg ( imgs , 'cover' ) || findImg ( imgs , 'folder' ) || findImg ( imgs , 'front' ) || imgs [ 0 ] ;
432387
433388 // case-insensitive sorting with international charset support - thanks https://stackoverflow.com/a/40390844/2370385
0 commit comments