Skip to content

Commit 862c2e8

Browse files
committed
hotfix for code review
1 parent 052004d commit 862c2e8

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

app/utils/chat.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CACHE_URL_PREFIX, UPLOAD_URL } from "@/app/constant";
2-
// import heic2any from "heic2any";
32
import { RequestMessage } from "@/app/client/api";
43

54
export function compressImage(file: Blob, maxSize: number): Promise<string> {
@@ -42,14 +41,18 @@ export function compressImage(file: Blob, maxSize: number): Promise<string> {
4241
reader.onerror = reject;
4342

4443
if (file.type.includes("heic")) {
45-
const heic2any = require("heic2any");
46-
heic2any({ blob: file, toType: "image/jpeg" })
47-
.then((blob: Blob) => {
48-
reader.readAsDataURL(blob);
49-
})
50-
.catch((e: any) => {
51-
reject(e);
52-
});
44+
try {
45+
const heic2any = require("heic2any");
46+
heic2any({ blob: file, toType: "image/jpeg" })
47+
.then((blob: Blob) => {
48+
reader.readAsDataURL(blob);
49+
})
50+
.catch((e: any) => {
51+
reject(e);
52+
});
53+
} catch (e) {
54+
reject(e);
55+
}
5356
}
5457

5558
reader.readAsDataURL(file);
@@ -65,8 +68,12 @@ export async function preProcessImageContent(
6568
const result = [];
6669
for (const part of content) {
6770
if (part?.type == "image_url" && part?.image_url?.url) {
68-
const url = await cacheImageToBase64Image(part?.image_url?.url);
69-
result.push({ type: part.type, image_url: { url } });
71+
try {
72+
const url = await cacheImageToBase64Image(part?.image_url?.url);
73+
result.push({ type: part.type, image_url: { url } });
74+
} catch (error) {
75+
console.error("Error processing image URL:", error);
76+
}
7077
} else {
7178
result.push({ ...part });
7279
}
@@ -92,7 +99,7 @@ export function cacheImageToBase64Image(imageUrl: string) {
9299
}
93100
return Promise.resolve(imageCaches[imageUrl]);
94101
}
95-
return imageUrl;
102+
return Promise.resolve(imageUrl);
96103
}
97104

98105
export function base64Image2Blob(base64Data: string, contentType: string) {

0 commit comments

Comments
 (0)