fix: 修复 huanke-gemini 不处理 file 类型图片的问题
- 在 sendHuankeGeminiRequest 中添加对 type: 'file' 格式的处理
- 支持从 Chat API 传过来的 { type: 'file', mediaType, data/url } 格式
- 确保图片编辑请求能正确传递图片到 API
This commit is contained in:
parent
b8279e4b93
commit
2572db545c
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user