chore: refactor downloads

This commit is contained in:
Michel de Graaf
2025-11-18 14:11:25 +01:00
parent 467de9cb91
commit 79da19ed0f
5 changed files with 114 additions and 59 deletions
+9 -9
View File
@@ -242,8 +242,7 @@ impl DownloadPeer {
let client_guard = client_context
.read()
.map_err(|_| DownloadError::LockPoisoned)?;
let download_info =
client_guard.download_tokens.get(&token_u32).cloned();
let download_info = client_guard.get_download_by_token(token_u32).cloned();
drop(client_guard);
download_info.ok_or(DownloadError::TokenNotFound(token_u32))
@@ -318,13 +317,13 @@ impl DownloadPeer {
0.0
};
let _ =
dl.sender.send(DownloadStatus::InProgress {
bytes_downloaded: processor.total_bytes
as u64,
total_bytes: dl.size,
speed_bytes_per_sec: speed,
});
let status = DownloadStatus::InProgress {
bytes_downloaded: processor.total_bytes as u64,
total_bytes: dl.size,
speed_bytes_per_sec: speed,
};
let _ = dl.sender.send(status.clone());
client_context.write().unwrap().update_download_with_status(dl.token, status);
last_update_time = Instant::now();
}
@@ -422,6 +421,7 @@ impl DownloadPeer {
if let Some(ref dl) = download {
let _ = dl.sender.send(DownloadStatus::Queued);
client_context.write().unwrap().update_download_with_status(dl.token, DownloadStatus::Queued);
}
let mut stream = match stream {