@@ -550,15 +550,14 @@ export class ObjectStorage {
550
550
const delimiter = options ?. delimiter
551
551
552
552
const cursor = options ?. cursor ? decodeContinuationToken ( options ?. cursor ) : undefined
553
- const searchResult = await this . db . listObjectsV2 ( this . bucketId , {
553
+ let searchResult = await this . db . listObjectsV2 ( this . bucketId , {
554
554
prefix : options ?. prefix ,
555
555
delimiter : options ?. delimiter ,
556
556
maxKeys : limit + 1 ,
557
557
nextToken : cursor ,
558
558
startAfter : cursor || options ?. startAfter ,
559
559
} )
560
560
561
- let results = searchResult
562
561
let prevPrefix = ''
563
562
564
563
if ( delimiter ) {
@@ -575,32 +574,36 @@ export class ObjectStorage {
575
574
prevPrefix = currPrefix
576
575
delimitedResults . push ( {
577
576
id : null ,
578
- name : options ?. encodingType === 'url' ? encodeURIComponent ( currPrefix ) : currPrefix ,
577
+ name : currPrefix ,
579
578
bucket_id : object . bucket_id ,
580
579
} )
581
580
continue
582
581
}
583
582
584
- delimitedResults . push ( {
585
- ...object ,
586
- name : options ?. encodingType === 'url' ? encodeURIComponent ( object . name ) : object . name ,
587
- } )
583
+ delimitedResults . push ( object )
588
584
}
589
- results = delimitedResults
585
+ searchResult = delimitedResults
590
586
}
591
587
592
588
let isTruncated = false
593
589
594
- if ( results . length > limit ) {
595
- results = results . slice ( 0 , limit )
590
+ if ( searchResult . length > limit ) {
591
+ searchResult = searchResult . slice ( 0 , limit )
596
592
isTruncated = true
597
593
}
598
594
599
- const folders = results . filter ( ( obj ) => obj . id === null )
600
- const objects = results . filter ( ( obj ) => obj . id !== null )
595
+ const folders : Obj [ ] = [ ]
596
+ const objects : Obj [ ] = [ ]
597
+ searchResult . forEach ( ( obj ) => {
598
+ const target = obj . id === null ? folders : objects
599
+ target . push ( {
600
+ ...obj ,
601
+ name : options ?. encodingType === 'url' ? encodeURIComponent ( obj . name ) : obj . name ,
602
+ } )
603
+ } )
601
604
602
605
const nextContinuationToken = isTruncated
603
- ? encodeContinuationToken ( results [ results . length - 1 ] . name )
606
+ ? encodeContinuationToken ( searchResult [ searchResult . length - 1 ] . name )
604
607
: undefined
605
608
606
609
return {
0 commit comments