(imageName: string)
| 96 | * Extract a mask from ZIP. |
| 97 | */ |
| 98 | export async function fetchZipMask(imageName: string): Promise<File | null> { |
| 99 | const cached = zipMaskState.getCached(imageName); |
| 100 | if (cached) return cached; |
| 101 | |
| 102 | if (!hasActiveZipArchive()) return null; |
| 103 | |
| 104 | if (zipMaskState.isRequestPending(imageName)) { |
| 105 | return zipMaskState.waitForRequest(imageName); |
| 106 | } |
| 107 | |
| 108 | const imageIndex = getActiveZipImageIndex(); |
| 109 | if (!imageIndex) return null; |
| 110 | |
| 111 | zipMaskState.startRequest(imageName); |
| 112 | let result: File | null = null; |
| 113 | |
| 114 | try { |
| 115 | for (const maskPath of getMaskPathVariants(imageName)) { |
| 116 | const entry = findZipEntry(maskPath, imageIndex); |
| 117 | if (entry) { |
| 118 | try { |
| 119 | const file = await entry.extract(); |
| 120 | zipMaskState.setCached(imageName, file); |
| 121 | result = file; |
| 122 | appLogger.info(`[ZIP Mask] Found mask for ${imageName}`); |
| 123 | return file; |
| 124 | } catch (err) { |
| 125 | appLogger.debug(`[ZIP Mask] Error extracting ${maskPath}:`, err); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | appLogger.debug(`[ZIP Mask] No mask found for ${imageName}`); |
| 131 | return null; |
| 132 | } finally { |
| 133 | zipMaskState.completeRequest(imageName, result); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Remove specific entries from the ZIP mask cache. |
no test coverage detected