Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
  • Loading branch information
flakey5 committed Dec 24, 2024
1 parent 019f2cf commit b0cdb16
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/providers/r2Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ import type {
} from './provider';
import { S3Provider } from './s3Provider';

type CachedFile = {
name: string;
lastModified: string | Date;
size: number;
};

type CachedDirectory = {
subdirectories: string[];
hasIndexHtmlFile: boolean;
files: CachedFile[] | File[];
lastModified: string | Date;
};

type R2ProviderCtorOptions = {
ctx: Context;
};
Expand Down Expand Up @@ -87,20 +100,19 @@ export class R2Provider implements Provider {
options?: ReadDirectoryOptions
): Promise<ReadDirectoryResult | undefined> {
if (path in CACHED_DIRECTORIES) {
// @ts-expect-error dates may not be parsed at this point, we take care
// of it below
const result: ReadDirectoryResult = CACHED_DIRECTORIES[path];

for (const file of result.files) {
if (typeof file.lastModified === 'string') {
file.lastModified = new Date(file.lastModified);
}
}
const result: CachedDirectory =
CACHED_DIRECTORIES[path as keyof typeof CACHED_DIRECTORIES];

if (typeof result.lastModified === 'string') {
result.lastModified = new Date(result.lastModified);

for (const file of result.files) {
// @ts-expect-error this isn't readonly
file.lastModified = new Date(file.lastModified);
}
}

// @ts-expect-error at this point the result is parsed already
return Promise.resolve({
subdirectories: result.subdirectories,
files: result.files,
Expand Down

0 comments on commit b0cdb16

Please sign in to comment.