fix: 修复Gemini上传响应解析错误
问题修复: - 修复UploadResponse结构体缺少urn字段的问题 - 支持Google Cloud Storage标准响应格式 - 优先使用urn字段作为文件URI - 添加name字段作为备用URI构建方案 根据日志分析: - API返回的是GCS标准格式,包含urn而非file_uri - 响应示例: gs://dy-media-storage/video-analysis/filename.mp4 - 解决了'missing field file_uri'错误 修复效果: - 支持多种URI格式的解析 - 提供更好的错误处理和日志 - 确保视频上传流程的完整性 现在应该能正确解析上传响应并继续AI分析流程。
This commit is contained in:
parent
b0ea168db8
commit
5d17966c43
|
|
@ -34,7 +34,9 @@ struct TokenResponse {
|
||||||
/// Gemini上传响应
|
/// Gemini上传响应
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct UploadResponse {
|
struct UploadResponse {
|
||||||
file_uri: String,
|
file_uri: Option<String>,
|
||||||
|
urn: Option<String>,
|
||||||
|
name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gemini内容生成请求
|
/// Gemini内容生成请求
|
||||||
|
|
@ -250,8 +252,14 @@ impl GeminiService {
|
||||||
let upload_response: UploadResponse = serde_json::from_str(&response_text)
|
let upload_response: UploadResponse = serde_json::from_str(&response_text)
|
||||||
.map_err(|e| anyhow!("解析上传响应失败: {} - 响应内容: {}", e, response_text))?;
|
.map_err(|e| anyhow!("解析上传响应失败: {} - 响应内容: {}", e, response_text))?;
|
||||||
|
|
||||||
println!("✅ 视频上传成功,文件URI: {}", upload_response.file_uri);
|
// 优先使用urn字段,如果没有则使用file_uri字段
|
||||||
Ok(upload_response.file_uri)
|
let file_uri = upload_response.urn
|
||||||
|
.or(upload_response.file_uri)
|
||||||
|
.or_else(|| upload_response.name.map(|name| format!("gs://dy-media-storage/{}", name)))
|
||||||
|
.ok_or_else(|| anyhow!("上传响应中未找到文件URI,响应内容: {}", response_text))?;
|
||||||
|
|
||||||
|
println!("✅ 视频上传成功,文件URI: {}", file_uri);
|
||||||
|
Ok(file_uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 生成内容分析
|
/// 生成内容分析
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue