web: fix "too much recursion" error

This commit is contained in:
Abdullah Atta
2024-08-02 15:48:40 +05:00
committed by Abdullah Atta
parent 1b71edef45
commit 438d412ae9
4 changed files with 26 additions and 1 deletions

View File

@@ -57,6 +57,9 @@ export class IndexedDBFileStore implements IFileStorage {
(k as string).startsWith(chunkPrefix)
) as string[];
}
async list(): Promise<string[]> {
return (await this.storage.keys()) as string[];
}
}
export class CacheStorageFileStore implements IFileStorage {
@@ -122,6 +125,12 @@ export class CacheStorageFileStore implements IFileStorage {
.map((r) => r.url.slice(1));
}
async list(): Promise<string[]> {
const cache = await this.getCache();
const keys = await cache.keys();
return keys.map((r) => r.url.slice(1));
}
private toURL(chunkName: string) {
return `/${chunkName}`;
}
@@ -176,4 +185,8 @@ export class OriginPrivateFileSystem implements IFileStorage {
await this.create();
return (await this.worker.listChunks(this.name, chunkPrefix)) || [];
}
async list(): Promise<string[]> {
await this.create();
return (await this.worker.list(this.name)) || [];
}
}

View File

@@ -101,6 +101,14 @@ class OriginPrivateFileStore implements IFileStorage {
return chunks;
}
async list(): Promise<string[]> {
const chunks: string[] = [];
for await (const entry of this.directory.keys()) {
chunks.push(entry);
}
return chunks;
}
private async safeOp<T>(chunkName: string, createPromise: () => Promise<T>) {
const lock = this.locks.get(chunkName);
if (lock) await lock;
@@ -150,6 +158,9 @@ const workerModule = {
},
async listChunks(directoryName: string, chunkPrefix: string) {
return (await fileStores.get(directoryName)?.listChunks(chunkPrefix)) || [];
},
async list(directoryName: string) {
return (await fileStores.get(directoryName)?.list()) || [];
}
};