mirror of
https://github.com/dergigi/boris.git
synced 2026-01-04 23:44:21 +01:00
fix: improve image cache resilience for offline viewing
- Clean up stale metadata when Cache API doesn't have cached data - Handle online/offline state properly in image loading - Show original URL when online, blob URL from cache when offline - Prevent cache misses when browser clears Cache API on hard reload
This commit is contained in:
@@ -162,6 +162,13 @@ async function getCachedImageUrl(url: string): Promise<string | null> {
|
||||
const response = await cache.match(url)
|
||||
|
||||
if (!response) {
|
||||
// Cache miss - clean up stale metadata if it exists
|
||||
const metadata = getMetadata()
|
||||
if (metadata[url]) {
|
||||
delete metadata[url]
|
||||
saveMetadata(metadata)
|
||||
console.log('🧹 Cleaned up stale cache metadata for:', url.substring(0, 50))
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -175,7 +182,8 @@ async function getCachedImageUrl(url: string): Promise<string | null> {
|
||||
// Convert response to blob URL
|
||||
const blob = await response.blob()
|
||||
return URL.createObjectURL(blob)
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.warn('Failed to load from cache:', err)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user