MCPcopy Index your code
hub / github.com/ChatGPTNextWeb/NextChat / cacheImageToBase64Image

Function cacheImageToBase64Image

app/utils/chat.ts:114–132  ·  view source on GitHub ↗
(imageUrl: string)

Source from the content-addressed store, hash-verified

112
113const imageCaches: Record<string, string> = {};
114export 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
134export function base64Image2Blob(base64Data: string, contentType: string) {
135 const byteCharacters = atob(base64Data);

Callers 1

Calls 2

fetchFunction · 0.90
compressImageFunction · 0.85

Tested by

no test coverage detected