@@ -16,6 +16,19 @@ import type {
1616} from './provider' ;
1717import { S3Provider } from './s3Provider' ;
1818
19+ type CachedFile = {
20+ name : string ;
21+ lastModified : string | Date ;
22+ size : number ;
23+ } ;
24+
25+ type CachedDirectory = {
26+ subdirectories : string [ ] ;
27+ hasIndexHtmlFile : boolean ;
28+ files : CachedFile [ ] | File [ ] ;
29+ lastModified : string | Date ;
30+ } ;
31+
1932type R2ProviderCtorOptions = {
2033 ctx : Context ;
2134} ;
@@ -88,20 +101,19 @@ export class R2Provider implements Provider {
88101 options ?: ReadDirectoryOptions
89102 ) : Promise < ReadDirectoryResult | undefined > {
90103 if ( path in CACHED_DIRECTORIES ) {
91- // @ts -expect-error dates may not be parsed at this point, we take care
92- // of it below
93- const result : ReadDirectoryResult = CACHED_DIRECTORIES [ path ] ;
94-
95- for ( const file of result . files ) {
96- if ( typeof file . lastModified === 'string' ) {
97- file . lastModified = new Date ( file . lastModified ) ;
98- }
99- }
104+ const result : CachedDirectory =
105+ CACHED_DIRECTORIES [ path as keyof typeof CACHED_DIRECTORIES ] ;
100106
101107 if ( typeof result . lastModified === 'string' ) {
102108 result . lastModified = new Date ( result . lastModified ) ;
109+
110+ for ( const file of result . files ) {
111+ // @ts -expect-error this isn't readonly
112+ file . lastModified = new Date ( file . lastModified ) ;
113+ }
103114 }
104115
116+ // @ts -expect-error at this point the result is parsed already
105117 return Promise . resolve ( {
106118 subdirectories : result . subdirectories ,
107119 files : result . files ,
0 commit comments