-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathutil.ts
More file actions
44 lines (36 loc) · 1.21 KB
/
util.ts
File metadata and controls
44 lines (36 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { env } from 'cloudflare:test';
import { inject } from 'vitest';
import type { Env } from '../env';
import type { Directory } from '../../vitest-setup';
async function populateR2BucketDirectory(directory: Directory): Promise<void> {
const promises: Array<Promise<unknown>> = [];
for (const path of Object.keys(directory.files)) {
const file = directory.files[path];
promises.push(
env.R2_BUCKET.put(path, file.contents, {
customMetadata: {
// This is added by rclone when copying the release assets to the
// bucket.
mtime: `${file.lastModified}`,
},
})
);
}
promises.push(
...Object.values(directory.subdirectories).map(populateR2BucketDirectory)
);
await Promise.all(promises);
}
/**
* Writes the contents of the dev bucket into the R2 bucket given in {@link env}
*/
export async function populateR2WithDevBucket(): Promise<void> {
// Grab the contents of the dev bucket
const devBucket = inject('devBucket');
// Write it to R2
await populateR2BucketDirectory(devBucket);
}
declare module 'cloudflare:test' {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface ProvidedEnv extends Env {}
}