Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: fix "too much recursion" error

Abdullah Atta438d412ae909
diff --git a/apps/web/src/interfaces/file-store.ts b/apps/web/src/interfaces/file-store.ts
index a74e6d83f..efaf65332 100644
--- a/apps/web/src/interfaces/file-store.ts
+++ b/apps/web/src/interfaces/file-store.ts
@@ -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)) || [];
+ }
}
diff --git a/apps/web/src/interfaces/opfs.worker.ts b/apps/web/src/interfaces/opfs.worker.ts
index 414c49132..752a5fe33 100644
--- a/apps/web/src/interfaces/opfs.worker.ts
+++ b/apps/web/src/interfaces/opfs.worker.ts
@@ -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()) || [];
}
};
diff --git a/packages/streamable-fs/index.ts b/packages/streamable-fs/index.ts
index 027e0d850..1ad865411 100644
--- a/packages/streamable-fs/index.ts
+++ b/packages/streamable-fs/index.ts
@@ -59,7 +59,7 @@ export class StreamableFS implements IStreamableFS {
}
async list(): Promise<string[]> {
- return this.list();
+ return this.storage.list();
}
async deleteFile(filename: string): Promise<boolean> {
diff --git a/packages/streamable-fs/src/interfaces.ts b/packages/streamable-fs/src/interfaces.ts
index 74af3382d..ef44b1de7 100644
--- a/packages/streamable-fs/src/interfaces.ts
+++ b/packages/streamable-fs/src/interfaces.ts
@@ -37,4 +37,5 @@ export interface IFileStorage {
deleteChunk(chunkName: string): Promise<void>;
readChunk(chunkName: string): Promise<Uint8Array | undefined>;
listChunks(chunkPrefix: string): Promise<string[]>;
+ list(): Promise<string[]>;
}