Skip to content

Commit b0cdb16

Browse files
committed
review
Signed-off-by: flakey5 <[email protected]>
1 parent 019f2cf commit b0cdb16

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/providers/r2Provider.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ import type {
1515
} from './provider';
1616
import { 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+
1831
type 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

Comments
 (0)