hotfix for code review
This commit is contained in:
parent
052004d70e
commit
862c2e8810
|
@ -1,5 +1,4 @@
|
||||||
import { CACHE_URL_PREFIX, UPLOAD_URL } from "@/app/constant";
|
import { CACHE_URL_PREFIX, UPLOAD_URL } from "@/app/constant";
|
||||||
// import heic2any from "heic2any";
|
|
||||||
import { RequestMessage } from "@/app/client/api";
|
import { RequestMessage } from "@/app/client/api";
|
||||||
|
|
||||||
export function compressImage(file: Blob, maxSize: number): Promise<string> {
|
export function compressImage(file: Blob, maxSize: number): Promise<string> {
|
||||||
|
@ -42,6 +41,7 @@ export function compressImage(file: Blob, maxSize: number): Promise<string> {
|
||||||
reader.onerror = reject;
|
reader.onerror = reject;
|
||||||
|
|
||||||
if (file.type.includes("heic")) {
|
if (file.type.includes("heic")) {
|
||||||
|
try {
|
||||||
const heic2any = require("heic2any");
|
const heic2any = require("heic2any");
|
||||||
heic2any({ blob: file, toType: "image/jpeg" })
|
heic2any({ blob: file, toType: "image/jpeg" })
|
||||||
.then((blob: Blob) => {
|
.then((blob: Blob) => {
|
||||||
|
@ -50,6 +50,9 @@ export function compressImage(file: Blob, maxSize: number): Promise<string> {
|
||||||
.catch((e: any) => {
|
.catch((e: any) => {
|
||||||
reject(e);
|
reject(e);
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
|
@ -65,8 +68,12 @@ export async function preProcessImageContent(
|
||||||
const result = [];
|
const result = [];
|
||||||
for (const part of content) {
|
for (const part of content) {
|
||||||
if (part?.type == "image_url" && part?.image_url?.url) {
|
if (part?.type == "image_url" && part?.image_url?.url) {
|
||||||
|
try {
|
||||||
const url = await cacheImageToBase64Image(part?.image_url?.url);
|
const url = await cacheImageToBase64Image(part?.image_url?.url);
|
||||||
result.push({ type: part.type, image_url: { url } });
|
result.push({ type: part.type, image_url: { url } });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error processing image URL:", error);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result.push({ ...part });
|
result.push({ ...part });
|
||||||
}
|
}
|
||||||
|
@ -92,7 +99,7 @@ export function cacheImageToBase64Image(imageUrl: string) {
|
||||||
}
|
}
|
||||||
return Promise.resolve(imageCaches[imageUrl]);
|
return Promise.resolve(imageCaches[imageUrl]);
|
||||||
}
|
}
|
||||||
return imageUrl;
|
return Promise.resolve(imageUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function base64Image2Blob(base64Data: string, contentType: string) {
|
export function base64Image2Blob(base64Data: string, contentType: string) {
|
||||||
|
|
Loading…
Reference in New Issue