feat(tui): added option for storing downloaded files in username directories

This commit is contained in:
Maik Steiger
2026-10-08 21:59:23 +02:00
parent 20bd676e0f
commit e567fa75ed
30 changed files with 130 additions and 7 deletions
+7 -3
View File
@@ -1148,9 +1148,13 @@ fn main() {
let completed = completed.clone();
workers.push(std::thread::spawn(move || {
Metrics::bump(&metrics.downloads_issued);
let Ok((_download, status_rx)) =
client.download(filename.clone(), peer.clone(), size, dir)
else {
let Ok((_download, status_rx)) = client.download(
filename.clone(),
peer.clone(),
size,
dir,
false,
) else {
return;
};
let deadline = run_deadline;
+4
View File
@@ -99,12 +99,14 @@ impl Client {
username: String,
size: u64,
download_directory: String,
use_username_dirs: bool,
) -> Result<(Download, Receiver<DownloadStatus>)> {
self.download_with_metadata(
filename,
username,
size,
download_directory,
use_username_dirs,
DownloadMetadata::default(),
)
}
@@ -115,6 +117,7 @@ impl Client {
username: String,
size: u64,
download_directory: String,
use_username_dirs: bool,
metadata: DownloadMetadata,
) -> Result<(Download, Receiver<DownloadStatus>)> {
info!("[client] Downloading {} from {}", filename, username);
@@ -132,6 +135,7 @@ impl Client {
token,
size,
download_directory,
use_username_dirs,
status: DownloadStatus::Queued,
sender: download_sender,
queue_position: None,
+1
View File
@@ -23,6 +23,7 @@ fn download(
token,
size: 100,
download_directory: "test".to_string(),
use_username_dirs: false,
status,
sender,
queue_position: None,
@@ -97,6 +97,7 @@ fn download_without_a_connection_resolves_failed() {
"peer".to_string(),
100,
"test".to_string(),
false,
)
.expect("download() should return a handle");
assert!(matches!(
+1
View File
@@ -242,6 +242,7 @@ mod tests {
token,
size: 100,
download_directory: "test".to_string(),
use_username_dirs: false,
status,
sender: mpsc::channel().0,
queue_position: None,
@@ -110,6 +110,10 @@ fn resolve_download_path(download: &Download) -> Result<String, DownloadError> {
.to_path_buf();
}
if download.use_username_dirs {
expanded_path = expanded_path.join(download.username.as_str());
}
let final_path =
expanded_path.join(extract_filename_from_path(&download.filename));
@@ -635,6 +639,7 @@ mod tests {
token: 1,
size,
download_directory: dir.display().to_string(),
use_username_dirs: false,
status: DownloadStatus::Queued,
sender: mpsc::channel().0,
queue_position: None,
+1
View File
@@ -479,6 +479,7 @@ mod tests {
token,
size: 100,
download_directory: std::env::temp_dir().display().to_string(),
use_username_dirs: false,
status: DownloadStatus::Queued,
sender: mpsc::channel().0,
queue_position: None,
+1
View File
@@ -185,6 +185,7 @@ pub struct Download {
pub token: u32,
pub size: u64,
pub download_directory: String,
pub use_username_dirs: bool,
pub status: DownloadStatus,
pub sender: Sender<DownloadStatus>,
pub queue_position: Option<u32>,