diff --git a/src/storage/adapters/opfsStorage.ts b/src/storage/adapters/opfsStorage.ts index affd625b..b7989f79 100644 --- a/src/storage/adapters/opfsStorage.ts +++ b/src/storage/adapters/opfsStorage.ts @@ -632,7 +632,8 @@ export class OPFSStorage extends BaseStorage { ): Promise => { try { for await (const [name, handle] of dirHandle.entries()) { - await dirHandle.removeEntry(name) + // Use recursive option to handle directories that may contain files + await dirHandle.removeEntry(name, { recursive: true }) } } catch (error) { console.error(`Error removing directory contents:`, error) diff --git a/src/storage/storageFactory.ts b/src/storage/storageFactory.ts index be64030e..81450b40 100644 --- a/src/storage/storageFactory.ts +++ b/src/storage/storageFactory.ts @@ -6,8 +6,9 @@ import {StorageAdapter} from '../coreTypes.js' import {MemoryStorage} from './adapters/memoryStorage.js' import {OPFSStorage} from './adapters/opfsStorage.js' -import {FileSystemStorage} from './adapters/fileSystemStorage.js' import {S3CompatibleStorage, R2Storage} from './adapters/s3CompatibleStorage.js' +import {FileSystemStorage} from './adapters/fileSystemStorage.js' +import {isBrowser} from '../utils/environment.js' /** * Options for creating a storage adapter @@ -182,7 +183,12 @@ export async function createStorage( // If file system storage is forced, use it regardless of other options if (options.forceFileSystemStorage) { + if (isBrowser()) { + console.warn('FileSystemStorage is not available in browser environments, falling back to memory storage') + return new MemoryStorage() + } console.log('Using file system storage (forced)') + const {FileSystemStorage} = await import('./adapters/fileSystemStorage.js') return new FileSystemStorage(options.rootDirectory || './brainy-data') } @@ -213,9 +219,15 @@ export async function createStorage( } } - case 'filesystem': + case 'filesystem': { + if (isBrowser()) { + console.warn('FileSystemStorage is not available in browser environments, falling back to memory storage') + return new MemoryStorage() + } console.log('Using file system storage') + const {FileSystemStorage} = await import('./adapters/fileSystemStorage.js') return new FileSystemStorage(options.rootDirectory || './brainy-data') + } case 's3': if (options.s3Storage) { @@ -362,4 +374,4 @@ export { FileSystemStorage, S3CompatibleStorage, R2Storage -} \ No newline at end of file +} diff --git a/test-fix.js b/test-fix.js deleted file mode 100644 index dc3c0f80..00000000 --- a/test-fix.js +++ /dev/null @@ -1,20 +0,0 @@ -// Simple test script to verify the FileSystemStorage fix -const { createStorage } = require('./dist/unified.js'); - -async function testFileSystemStorage() { - try { - console.log('Creating storage with forceFileSystemStorage: true'); - const storage = await createStorage({ forceFileSystemStorage: true }); - console.log('Storage created successfully'); - - console.log('Initializing storage'); - await storage.init(); - console.log('Storage initialized successfully'); - - console.log('Test passed: No TypeError about undefined path.join'); - } catch (error) { - console.error('Test failed with error:', error); - } -} - -testFileSystemStorage();