From 2572db545c6fcfb011e40704de3e89b3e9914547 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 2 Feb 2026 00:25:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20huanke-gemini=20?= =?UTF-8?q?=E4=B8=8D=E5=A4=84=E7=90=86=20file=20=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 sendHuankeGeminiRequest 中添加对 type: 'file' 格式的处理 - 支持从 Chat API 传过来的 { type: 'file', mediaType, data/url } 格式 - 确保图片编辑请求能正确传递图片到 API --- lib/ai/providers/huanke-gemini.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/ai/providers/huanke-gemini.ts b/lib/ai/providers/huanke-gemini.ts index f743fff..5696a68 100644 --- a/lib/ai/providers/huanke-gemini.ts +++ b/lib/ai/providers/huanke-gemini.ts @@ -443,6 +443,35 @@ async function sendHuankeGeminiRequest( } }); console.log("[Huanke Gemini] Added image URL:", imageUrl.substring(0, 100)); + } else if (contentPart.type === "file" && (contentPart.data || contentPart.url)) { + // 🆕 处理 file 类型(从 Chat API 传过来的格式) + // 格式: { type: "file", mediaType: "image/jpeg", data: "https://..." } + let imageUrl = contentPart.data || contentPart.url; + const mimeType = contentPart.mediaType || contentPart.mimeType || "image/jpeg"; + + console.log("[Huanke Gemini] Processing file type:", { url: imageUrl?.substring(0, 80), mimeType }); + + if (imageUrl && imageUrl.startsWith("data:")) { + // Base64 图片 -> 上传到 S3 获取 URL + console.log("[Huanke Gemini] Converting Base64 file to URL (Base64 forbidden)..."); + try { + imageUrl = await convertBase64ToUrl(imageUrl); + } catch (error) { + console.error("[Huanke Gemini] Failed to convert Base64 to URL:", error); + continue; + } + } + + if (imageUrl && imageUrl.startsWith("http")) { + // 使用 fileData 格式传递图片 URL + parts.push({ + fileData: { + fileUri: imageUrl, + mimeType: mimeType.startsWith("image/") ? mimeType : "image/jpeg", + } + }); + console.log("[Huanke Gemini] Added file image URL:", imageUrl.substring(0, 100)); + } } } }