@@ -18,6 +18,23 @@ async function s3list(bucket: string, prefix: string): Promise<S3ListItem[]> {
1818 const text = await result . text ( )
1919 const results : S3ListItem [ ] = [ ]
2020
21+ // Parse CommonPrefixes (virtual directories)
22+ const prefixRegex = / < C o m m o n P r e f i x e s > ( .* ?) < \/ C o m m o n P r e f i x e s > / gs
23+ const prefixMatches = text . match ( prefixRegex ) ?? [ ]
24+
25+ for ( const match of prefixMatches ) {
26+ const prefixMatch = / < P r e f i x > ( .* ?) < \/ P r e f i x > / . exec ( match )
27+ if ( ! prefixMatch ) continue
28+
29+ const key = prefixMatch [ 1 ]
30+ results . push ( {
31+ key,
32+ lastModified : new Date ( ) . toISOString ( ) , // No lastModified for CommonPrefixes
33+ size : 0 ,
34+ isCommonPrefix : true ,
35+ } )
36+ }
37+
2138 // Parse regular objects (files and explicit directories)
2239 const contentsRegex = / < C o n t e n t s > ( .* ?) < \/ C o n t e n t s > / gs
2340 const contentsMatches = text . match ( contentsRegex ) ?? [ ]
@@ -38,23 +55,6 @@ async function s3list(bucket: string, prefix: string): Promise<S3ListItem[]> {
3855 results . push ( { key, lastModified, size, eTag } )
3956 }
4057
41- // Parse CommonPrefixes (virtual directories)
42- const prefixRegex = / < C o m m o n P r e f i x e s > ( .* ?) < \/ C o m m o n P r e f i x e s > / gs
43- const prefixMatches = text . match ( prefixRegex ) ?? [ ]
44-
45- for ( const match of prefixMatches ) {
46- const prefixMatch = / < P r e f i x > ( .* ?) < \/ P r e f i x > / . exec ( match )
47- if ( ! prefixMatch ) continue
48-
49- const key = prefixMatch [ 1 ]
50- results . push ( {
51- key,
52- lastModified : new Date ( ) . toISOString ( ) , // No lastModified for CommonPrefixes
53- size : 0 ,
54- isCommonPrefix : true ,
55- } )
56- }
57-
5858 return results
5959}
6060
@@ -101,7 +101,8 @@ export function getHttpSource(sourceId: string, options?: {requestInit?: Request
101101 prefix,
102102 listFiles : ( ) => s3list ( bucket , prefix ) . then ( items =>
103103 items
104- . filter ( item => item . key !== undefined )
104+ // skip s3 directory placeholder
105+ . filter ( item => item . key !== undefined && item . key !== prefix )
105106 . map ( item => {
106107 if ( ! item . key ) {
107108 throw new Error ( 'Key is undefined' )
0 commit comments