Bluesky app fork with some witchin' additions 💫

fix copy-to-cache (#9799)

authored by samuel.fm and committed by

GitHub ee99320e 9689a6da

+17 -16
+17 -16
src/state/gallery.ts
··· 270 270 * On web, converts blob URLs to data URIs immediately to prevent revocation issues. 271 271 */ 272 272 async function copyToCache(from: string): Promise<string> { 273 - // Handle web blob URLs - convert to data URI immediately before they can be revoked 274 - if (IS_WEB && from.startsWith('blob:')) { 275 - try { 276 - const response = await fetch(from) 277 - const blob = await response.blob() 278 - return await blobToDataUri(blob) 279 - } catch (e) { 280 - // If fetch fails, the blob URL was likely already revoked 281 - // Return as-is and let downstream code handle the error 282 - return from 283 - } 284 - } 285 - 286 273 // Data URIs don't need any conversion 287 274 if (from.startsWith('data:')) { 288 275 return from 289 276 } 290 277 291 - const cacheDir = IS_WEB && getImageCacheDirectory() 278 + if (IS_WEB) { 279 + // Web: convert blob URLs to data URIs before they can be revoked 280 + if (from.startsWith('blob:')) { 281 + try { 282 + const response = await fetch(from) 283 + const blob = await response.blob() 284 + return await blobToDataUri(blob) 285 + } catch (e) { 286 + // Blob URL was likely revoked, return as-is for downstream error handling 287 + return from 288 + } 289 + } 290 + // Other URLs on web don't need conversion 291 + return from 292 + } 292 293 293 - // On web (non-blob URLs) or if already in cache dir, no need to copy 294 + // Native: copy to cache directory to survive OS temp file cleanup 295 + const cacheDir = getImageCacheDirectory() 294 296 if (!cacheDir || from.startsWith(cacheDir)) { 295 297 return from 296 298 } ··· 298 300 const to = joinPath(cacheDir, nanoid(36)) 299 301 await makeDirectoryAsync(cacheDir, {intermediates: true}) 300 302 301 - // Normalize the source path for expo-file-system 302 303 let normalizedFrom = from 303 304 if (!from.startsWith('file://') && from.startsWith('/')) { 304 305 normalizedFrom = `file://${from}`