mirror of
https://github.com/cap153/LANChat.git
synced 2026-12-05 08:00:36 +00:00
fix: 安卓端文件消息离线不补发、离线用户 Share Intent 图片预览不渲染
This commit is contained in:
1 parent
84b41d923e
commit
b9aec6ef86
1 file changed
+29
-3
@@ -1215,18 +1215,44 @@ pub async fn send_file_from_fd(
|
||||
"[Command] 用户 {} 处于离线记录中,直接保存文件消息为挂起状态",
|
||||
peerId
|
||||
);
|
||||
let _ = crate::db::save_file_message(
|
||||
// 接管 FD 所有权,克隆一份用于缓存
|
||||
let android_file = AndroidFile::from_fd(fd)?;
|
||||
let std_file = android_file.into_file();
|
||||
let dup = std_file.try_clone()
|
||||
.map_err(|e| format!("FD 克隆失败: {}", e))?;
|
||||
let cached_fd = dup.into_raw_fd();
|
||||
// 原始 std_file 在此 drop 关闭原始 FD,cached_fd 是独立的新 FD
|
||||
drop(std_file);
|
||||
|
||||
// 先保存消息获取 msg_id
|
||||
let msg_id = crate::db::save_file_message(
|
||||
&state.pool,
|
||||
peerId.clone(),
|
||||
fileName.clone(),
|
||||
fileSize,
|
||||
format!("fd:{}", fd),
|
||||
"fd:temp".to_string(),
|
||||
"pending".to_string(),
|
||||
"pending".to_string(),
|
||||
).await;
|
||||
).await.map_err(|e| format!("创建记录失败: {}", e))?;
|
||||
|
||||
// 缓存克隆的 FD(用 msg_id 作为 key)
|
||||
crate::android_fd::cache_fd_for_msg(
|
||||
msg_id,
|
||||
cached_fd,
|
||||
fileName.clone(),
|
||||
fileSize as u64,
|
||||
);
|
||||
|
||||
// 更新 DB 路径为 fd:{msg_id}
|
||||
let fd_path = format!("fd:{}", msg_id);
|
||||
if let Err(e) = crate::db::update_file_path_by_id(&state.pool, msg_id, &fd_path).await {
|
||||
eprintln!("[Command] 更新 FD 文件路径失败: {}", e);
|
||||
}
|
||||
|
||||
return Ok(serde_json::json!({
|
||||
"success": true,
|
||||
"status": "pending",
|
||||
"msg_id": msg_id,
|
||||
"file_name": fileName,
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user