(imageUrl: string)
| 112 | |
| 113 | const imageCaches: Record<string, string> = {}; |
| 114 | export function cacheImageToBase64Image(imageUrl: string) { |
| 115 | if (imageUrl.includes(CACHE_URL_PREFIX)) { |
| 116 | if (!imageCaches[imageUrl]) { |
| 117 | const reader = new FileReader(); |
| 118 | return fetch(imageUrl, { |
| 119 | method: "GET", |
| 120 | mode: "cors", |
| 121 | credentials: "include", |
| 122 | }) |
| 123 | .then((res) => res.blob()) |
| 124 | .then( |
| 125 | async (blob) => |
| 126 | (imageCaches[imageUrl] = await compressImage(blob, 256 * 1024)), |
| 127 | ); // compressImage |
| 128 | } |
| 129 | return Promise.resolve(imageCaches[imageUrl]); |
| 130 | } |
| 131 | return Promise.resolve(imageUrl); |
| 132 | } |
| 133 | |
| 134 | export function base64Image2Blob(base64Data: string, contentType: string) { |
| 135 | const byteCharacters = atob(base64Data); |
no test coverage detected