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.
This commit is contained in:
parent
0a3b0c09b1
commit
c7987822e9
1 changed files with 11 additions and 3 deletions
|
|
@ -900,7 +900,7 @@ export async function createStorage(options: {
|
||||||
process.versions.node != null
|
process.versions.node != null
|
||||||
|
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
// In Node.js, use FileSystemStorage
|
// In Node.js, use FileSystemStorage first, then fall back to memory
|
||||||
try {
|
try {
|
||||||
const fileSystemModule = await import('./fileSystemStorage.js')
|
const fileSystemModule = await import('./fileSystemStorage.js')
|
||||||
return new fileSystemModule.FileSystemStorage()
|
return new fileSystemModule.FileSystemStorage()
|
||||||
|
|
@ -924,8 +924,16 @@ export async function createStorage(options: {
|
||||||
}
|
}
|
||||||
return opfsStorage
|
return opfsStorage
|
||||||
} else {
|
} else {
|
||||||
console.warn('OPFS is not available, falling back to in-memory storage')
|
// 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()
|
return new MemoryStorage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue