Skip to content

Commit

Permalink
storageBuckets.keys()
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiancook committed Dec 1, 2023
1 parent d3eafaf commit 0779f4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/storage-buckets/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ export interface InternalBucket {
delete(): Promise<void>
}

export async function listInternalStorageBucketNames() {
const keys = await listKeyValueStoreIndex();
const buckets = keys
.filter(key => key.startsWith("bucket:"))
.map(key => key.split(":")[1]);
return ["default", ...new Set(buckets)];
}

export function getInternalStorageBucket(bucket: string = "default"): InternalBucket {
const isDefault = bucket === "default";
const prefix = isDefault ? "" : `bucket:${bucket}:`
Expand Down
7 changes: 5 additions & 2 deletions src/storage-buckets/manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {StorageBucket, StorageBucketManager, StorageBucketOptions} from "./types";
import {Promise} from "@virtualstate/promise";
import {getInternalStorageBucket} from "./internal";
import {getInternalStorageBucket, listInternalStorageBucketNames} from "./internal";
import {DurableCacheStorage} from "../fetch";
import {getOrigin} from "../listen";
import {getConfig} from "../config";
Expand Down Expand Up @@ -83,7 +83,10 @@ export class DurableStorageBucketManager implements StorageBucketManager {
}

async keys(): Promise<string[]> {
return [];
return [...new Set([
...this.buckets.keys(),
...await listInternalStorageBucketNames()
])];
}

async open(name: string, options?: StorageBucketOptions): Promise<StorageBucket> {
Expand Down

0 comments on commit 0779f4f

Please sign in to comment.