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