(imageName: string)
| 45 | * Returns the cached File if already extracted, otherwise extracts and caches. |
| 46 | */ |
| 47 | export async function fetchZipImage(imageName: string): Promise<File | null> { |
| 48 | const cached = zipImageState.getCached(imageName); |
| 49 | if (cached) return cached; |
| 50 | |
| 51 | if (!hasActiveZipArchive()) return null; |
| 52 | |
| 53 | if (zipImageState.isRequestPending(imageName)) { |
| 54 | return zipImageState.waitForRequest(imageName); |
| 55 | } |
| 56 | |
| 57 | zipImageState.startRequest(imageName); |
| 58 | let result: File | null = null; |
| 59 | |
| 60 | try { |
| 61 | const extractedFile = await extractZipImage(imageName); |
| 62 | if (!extractedFile) { |
| 63 | return null; |
| 64 | } |
| 65 | |
| 66 | const filename = imageName.split('/').pop() || imageName; |
| 67 | const file = await compressAndResizeToJpeg(new Blob([await extractedFile.arrayBuffer()]), filename); |
| 68 | zipImageState.setCached(imageName, file); |
| 69 | result = file; |
| 70 | |
| 71 | return file; |
| 72 | } catch (err) { |
| 73 | appLogger.warn(`[ZIP Image] Error extracting ${imageName}:`, err); |
| 74 | return null; |
| 75 | } finally { |
| 76 | zipImageState.completeRequest(imageName, result); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Extract an image from ZIP without display-cache resizing or JPEG recompression. |
no test coverage detected