From c7987822e9c10124e7480ea5ad1070811f45e915 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Wed, 28 May 2025 16:18:59 -0700 Subject: [PATCH] feat: enhance fallback logic for storage initialization in opfsStorage Improved the fallback sequence for storage initialization by adding a secondary attempt to use FileSystemStorage in browser environments before defaulting to in-memory storage. Enhanced error handling and logging for unavailable storage options. --- src/storage/opfsStorage.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/storage/opfsStorage.ts b/src/storage/opfsStorage.ts index 933dd2ac..6b2f71b8 100644 --- a/src/storage/opfsStorage.ts +++ b/src/storage/opfsStorage.ts @@ -900,7 +900,7 @@ export async function createStorage(options: { process.versions.node != null if (isNode) { - // In Node.js, use FileSystemStorage + // In Node.js, use FileSystemStorage first, then fall back to memory try { const fileSystemModule = await import('./fileSystemStorage.js') return new fileSystemModule.FileSystemStorage() @@ -924,8 +924,16 @@ export async function createStorage(options: { } return opfsStorage } else { - console.warn('OPFS is not available, falling back to in-memory storage') - return new MemoryStorage() + // OPFS is not available, try to use FileSystem API if available + try { + // Try to load FileSystemStorage for browser environments + // Note: This will likely fail as FileSystemStorage is designed for Node.js + const fileSystemModule = await import('./fileSystemStorage.js') + return new fileSystemModule.FileSystemStorage() + } catch (error) { + console.warn('FileSystem storage is not available, falling back to in-memory storage') + return new MemoryStorage() + } } } }