保存图片按实际格式储存。

This commit is contained in:
xiaoski 2026-04-24 16:25:52 +08:00
parent 81dcc67932
commit 447cb2eee5

View File

@ -356,14 +356,28 @@ impl FeishuChannel {
return Err(ChannelError::Other(format!("Image download failed {}: {}", status, error_text)));
}
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("image/jpeg");
let ext = match content_type {
"image/png" => "png",
"image/gif" => "gif",
"image/webp" => "webp",
"image/bmp" => "bmp",
_ => "jpg",
};
let data = resp.bytes().await
.map_err(|e| ChannelError::Other(format!("Failed to read image data: {}", e)))?
.to_vec();
#[cfg(debug_assertions)]
tracing::debug!(data_len = %data.len(), "Downloaded image data");
tracing::debug!(data_len = %data.len(), content_type = %content_type, "Downloaded image data");
let filename = format!("{}_{}.jpg", message_id, &image_key[..8.min(image_key.len())]);
let filename = format!("{}_{}.{}", message_id, &image_key[..8.min(image_key.len())], ext);
let file_path = media_dir.join(&filename);
tokio::fs::write(&file_path, &data).await