fix: linting
This commit is contained in:
@@ -384,7 +384,7 @@ impl Client {
|
|||||||
username: String,
|
username: String,
|
||||||
size: u64,
|
size: u64,
|
||||||
download_directory: String,
|
download_directory: String,
|
||||||
) -> Result<Receiver<DownloadStatus>> {
|
) -> Result<(Download, Receiver<DownloadStatus>)> {
|
||||||
info!("[client] Downloading {} from {}", filename, username);
|
info!("[client] Downloading {} from {}", filename, username);
|
||||||
|
|
||||||
let hash = md5::md5(&filename);
|
let hash = md5::md5(&filename);
|
||||||
@@ -421,10 +421,13 @@ impl Client {
|
|||||||
|
|
||||||
if !download_initiated {
|
if !download_initiated {
|
||||||
let _ = download.sender.send(DownloadStatus::Failed);
|
let _ = download.sender.send(DownloadStatus::Failed);
|
||||||
self.context.write().unwrap().update_download_with_status(token, DownloadStatus::Failed);
|
self.context
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.update_download_with_status(token, DownloadStatus::Failed);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(download_receiver)
|
Ok((download, download_receiver))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_failed_uploads(
|
fn process_failed_uploads(
|
||||||
@@ -811,7 +814,13 @@ impl Client {
|
|||||||
download.size
|
download.size
|
||||||
);
|
);
|
||||||
let _ = download.sender.send(DownloadStatus::Completed);
|
let _ = download.sender.send(DownloadStatus::Completed);
|
||||||
client_context.write().unwrap().update_download_with_status(download.token, DownloadStatus::Completed);
|
client_context
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.update_download_with_status(
|
||||||
|
download.token,
|
||||||
|
DownloadStatus::Completed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace!("[client] failed to download: {}", e);
|
trace!("[client] failed to download: {}", e);
|
||||||
|
|||||||
@@ -22,6 +22,4 @@ pub mod prelude {
|
|||||||
pub use actor::server_actor::PeerAddress;
|
pub use actor::server_actor::PeerAddress;
|
||||||
pub use client::{Client, ClientSettings};
|
pub use client::{Client, ClientSettings};
|
||||||
pub use error::{Result, SoulseekRs};
|
pub use error::{Result, SoulseekRs};
|
||||||
pub use types::{
|
pub use types::{DownloadStatus, File, Search, SearchResult, Transfer};
|
||||||
DownloadStatus, File, Search, SearchResult, Transfer,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -242,7 +242,8 @@ impl DownloadPeer {
|
|||||||
let client_guard = client_context
|
let client_guard = client_context
|
||||||
.read()
|
.read()
|
||||||
.map_err(|_| DownloadError::LockPoisoned)?;
|
.map_err(|_| DownloadError::LockPoisoned)?;
|
||||||
let download_info = client_guard.get_download_by_token(token_u32).cloned();
|
let download_info =
|
||||||
|
client_guard.get_download_by_token(token_u32).cloned();
|
||||||
drop(client_guard);
|
drop(client_guard);
|
||||||
|
|
||||||
download_info.ok_or(DownloadError::TokenNotFound(token_u32))
|
download_info.ok_or(DownloadError::TokenNotFound(token_u32))
|
||||||
@@ -323,7 +324,10 @@ impl DownloadPeer {
|
|||||||
speed_bytes_per_sec: speed,
|
speed_bytes_per_sec: speed,
|
||||||
};
|
};
|
||||||
let _ = dl.sender.send(status.clone());
|
let _ = dl.sender.send(status.clone());
|
||||||
client_context.write().unwrap().update_download_with_status(dl.token, status);
|
client_context
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.update_download_with_status(dl.token, status);
|
||||||
|
|
||||||
last_update_time = Instant::now();
|
last_update_time = Instant::now();
|
||||||
}
|
}
|
||||||
@@ -421,7 +425,10 @@ impl DownloadPeer {
|
|||||||
|
|
||||||
if let Some(ref dl) = download {
|
if let Some(ref dl) = download {
|
||||||
let _ = dl.sender.send(DownloadStatus::Queued);
|
let _ = dl.sender.send(DownloadStatus::Queued);
|
||||||
client_context.write().unwrap().update_download_with_status(dl.token, DownloadStatus::Queued);
|
client_context
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.update_download_with_status(dl.token, DownloadStatus::Queued);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut stream = match stream {
|
let mut stream = match stream {
|
||||||
|
|||||||
@@ -157,7 +157,14 @@ fn handle_file_connection(
|
|||||||
) {
|
) {
|
||||||
Ok((download, filename)) => {
|
Ok((download, filename)) => {
|
||||||
let _ = download.sender.send(DownloadStatus::Completed);
|
let _ = download.sender.send(DownloadStatus::Completed);
|
||||||
context.client_context.write().unwrap().update_download_with_status(download.token, DownloadStatus::Completed);
|
context
|
||||||
|
.client_context
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.update_download_with_status(
|
||||||
|
download.token,
|
||||||
|
DownloadStatus::Completed,
|
||||||
|
);
|
||||||
info!(
|
info!(
|
||||||
"Successfully downloaded {} bytes to {}",
|
"Successfully downloaded {} bytes to {}",
|
||||||
download.size, filename
|
download.size, filename
|
||||||
|
|||||||
@@ -102,13 +102,17 @@ impl Download {
|
|||||||
pub fn is_finished(&self) -> bool {
|
pub fn is_finished(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
self.status,
|
self.status,
|
||||||
DownloadStatus::Completed | DownloadStatus::Failed | DownloadStatus::TimedOut
|
DownloadStatus::Completed
|
||||||
|
| DownloadStatus::Failed
|
||||||
|
| DownloadStatus::TimedOut
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bytes_downloaded(&self) -> u64 {
|
pub fn bytes_downloaded(&self) -> u64 {
|
||||||
match &self.status {
|
match &self.status {
|
||||||
DownloadStatus::InProgress { bytes_downloaded, .. } => *bytes_downloaded,
|
DownloadStatus::InProgress {
|
||||||
|
bytes_downloaded, ..
|
||||||
|
} => *bytes_downloaded,
|
||||||
DownloadStatus::Completed => self.size,
|
DownloadStatus::Completed => self.size,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
}
|
}
|
||||||
@@ -116,7 +120,10 @@ impl Download {
|
|||||||
|
|
||||||
pub fn speed_bytes_per_sec(&self) -> f64 {
|
pub fn speed_bytes_per_sec(&self) -> f64 {
|
||||||
match &self.status {
|
match &self.status {
|
||||||
DownloadStatus::InProgress { speed_bytes_per_sec, .. } => *speed_bytes_per_sec,
|
DownloadStatus::InProgress {
|
||||||
|
speed_bytes_per_sec,
|
||||||
|
..
|
||||||
|
} => *speed_bytes_per_sec,
|
||||||
_ => 0.0,
|
_ => 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,10 @@ pub fn init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to open log file '{}': {}", log_file_path, e);
|
eprintln!(
|
||||||
|
"Failed to open log file '{}': {}",
|
||||||
|
log_file_path, e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,11 @@ pub struct Cli {
|
|||||||
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
|
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
|
||||||
pub verbose: u8,
|
pub verbose: u8,
|
||||||
|
|
||||||
#[arg(long, env = "LOG_FILE", help = "Write logs to file instead of stderr")]
|
#[arg(
|
||||||
|
long,
|
||||||
|
env = "LOG_FILE",
|
||||||
|
help = "Write logs to file instead of stderr"
|
||||||
|
)]
|
||||||
pub log_file: Option<PathBuf>,
|
pub log_file: Option<PathBuf>,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|||||||
|
|
||||||
pub struct MultiDownloadProgress {
|
pub struct MultiDownloadProgress {
|
||||||
downloads: Vec<DownloadEntry>,
|
downloads: Vec<DownloadEntry>,
|
||||||
receiver_channel: Receiver<(soulseek_rs::types::Download, Receiver<DownloadStatus>)>,
|
receiver_channel:
|
||||||
|
Receiver<(soulseek_rs::types::Download, Receiver<DownloadStatus>)>,
|
||||||
list_state: TableState,
|
list_state: TableState,
|
||||||
max_concurrent: usize,
|
max_concurrent: usize,
|
||||||
active_count: usize,
|
active_count: usize,
|
||||||
@@ -38,7 +39,10 @@ pub struct MultiDownloadProgress {
|
|||||||
|
|
||||||
impl MultiDownloadProgress {
|
impl MultiDownloadProgress {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
receiver_channel: Receiver<(soulseek_rs::types::Download, Receiver<DownloadStatus>)>,
|
receiver_channel: Receiver<(
|
||||||
|
soulseek_rs::types::Download,
|
||||||
|
Receiver<DownloadStatus>,
|
||||||
|
)>,
|
||||||
max_concurrent: usize,
|
max_concurrent: usize,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut list_state = TableState::default();
|
let mut list_state = TableState::default();
|
||||||
@@ -63,12 +67,15 @@ impl MultiDownloadProgress {
|
|||||||
terminal.draw(|frame| self.render(frame))?;
|
terminal.draw(|frame| self.render(frame))?;
|
||||||
|
|
||||||
// Check for incoming downloads from background thread
|
// Check for incoming downloads from background thread
|
||||||
while let Ok((download, receiver)) = self.receiver_channel.try_recv() {
|
while let Ok((download, receiver)) =
|
||||||
|
self.receiver_channel.try_recv()
|
||||||
|
{
|
||||||
self.downloads.push(DownloadEntry {
|
self.downloads.push(DownloadEntry {
|
||||||
download,
|
download,
|
||||||
receiver: Some(receiver),
|
receiver: Some(receiver),
|
||||||
});
|
});
|
||||||
self.queuing_status = format!("{} downloads queued", self.downloads.len());
|
self.queuing_status =
|
||||||
|
format!("{} downloads queued", self.downloads.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll all receivers for status updates
|
// Poll all receivers for status updates
|
||||||
@@ -229,8 +236,7 @@ impl MultiDownloadProgress {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let progress = if download.size > 0 {
|
let progress = if download.size > 0 {
|
||||||
download.bytes_downloaded() as f64
|
download.bytes_downloaded() as f64 / download.size as f64
|
||||||
/ download.size as f64
|
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
@@ -348,8 +354,10 @@ pub fn render_download_stats(
|
|||||||
.filter(|d| matches!(d.download.status, DownloadStatus::Queued))
|
.filter(|d| matches!(d.download.status, DownloadStatus::Queued))
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
let total_downloaded: u64 =
|
let total_downloaded: u64 = downloads
|
||||||
downloads.iter().map(|d| d.download.bytes_downloaded()).sum();
|
.iter()
|
||||||
|
.map(|d| d.download.bytes_downloaded())
|
||||||
|
.sum();
|
||||||
let total_size: u64 = downloads.iter().map(|d| d.download.size).sum();
|
let total_size: u64 = downloads.iter().map(|d| d.download.size).sum();
|
||||||
let overall_progress = if total_size > 0 {
|
let overall_progress = if total_size > 0 {
|
||||||
(total_downloaded as f64 / total_size as f64 * 100.0) as u8
|
(total_downloaded as f64 / total_size as f64 * 100.0) as u8
|
||||||
@@ -363,7 +371,9 @@ pub fn render_download_stats(
|
|||||||
};
|
};
|
||||||
let total_speed: f64 = downloads
|
let total_speed: f64 = downloads
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|d| matches!(d.download.status, DownloadStatus::InProgress { .. }))
|
.filter(|d| {
|
||||||
|
matches!(d.download.status, DownloadStatus::InProgress { .. })
|
||||||
|
})
|
||||||
.map(|d| d.download.speed_bytes_per_sec())
|
.map(|d| d.download.speed_bytes_per_sec())
|
||||||
.sum();
|
.sum();
|
||||||
let speed_mb = (total_speed / 1_048_576.0 * 100.0).round() / 100.0;
|
let speed_mb = (total_speed / 1_048_576.0 * 100.0).round() / 100.0;
|
||||||
@@ -461,7 +471,6 @@ pub fn show_multi_download_progress(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
soulseek_rs::utils::logger::enable_buffering();
|
soulseek_rs::utils::logger::enable_buffering();
|
||||||
|
|
||||||
// Create channel for sending downloads and receivers from background thread
|
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
|
|
||||||
// Spawn background thread to initialize downloads
|
// Spawn background thread to initialize downloads
|
||||||
@@ -475,21 +484,20 @@ pub fn show_multi_download_progress(
|
|||||||
size,
|
size,
|
||||||
download_dir.clone(),
|
download_dir.clone(),
|
||||||
) {
|
) {
|
||||||
Ok(receiver) => {
|
Ok((download, receiver)) => {
|
||||||
// Get the download from client
|
|
||||||
if let Some(download) = init_client.get_all_downloads().iter().find(|d| d.filename == filename && d.username == username).cloned() {
|
|
||||||
let _ = tx.send((download, receiver));
|
let _ = tx.send((download, receiver));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to start download for {}: {}", filename, e);
|
eprintln!(
|
||||||
|
"Failed to start download for {}: {}",
|
||||||
|
filename, e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut progress =
|
let mut progress = MultiDownloadProgress::new(rx, max_concurrent);
|
||||||
MultiDownloadProgress::new(rx, max_concurrent);
|
|
||||||
let result = progress.run(terminal);
|
let result = progress.run(terminal);
|
||||||
ratatui::restore();
|
ratatui::restore();
|
||||||
|
|
||||||
|
|||||||
@@ -776,6 +776,7 @@ impl MainTui {
|
|||||||
let download_dir = self.download_dir.clone();
|
let download_dir = self.download_dir.clone();
|
||||||
let sender = self.state.downloads_sender_channel.clone().unwrap();
|
let sender = self.state.downloads_sender_channel.clone().unwrap();
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
for (filename, username, size) in selected_files.into_iter() {
|
for (filename, username, size) in selected_files.into_iter() {
|
||||||
match client.download(
|
match client.download(
|
||||||
@@ -784,18 +785,9 @@ impl MainTui {
|
|||||||
size,
|
size,
|
||||||
download_dir.clone(),
|
download_dir.clone(),
|
||||||
) {
|
) {
|
||||||
Ok(rx) => {
|
Ok((download, rx)) => {
|
||||||
if let Some(download) = client
|
|
||||||
.get_all_downloads()
|
|
||||||
.iter()
|
|
||||||
.find(|d| {
|
|
||||||
d.filename == filename && d.username == username
|
|
||||||
})
|
|
||||||
.cloned()
|
|
||||||
{
|
|
||||||
let _ = sender.send((download, rx));
|
let _ = sender.send((download, rx));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Failed to start download for {}: {}",
|
"Failed to start download for {}: {}",
|
||||||
@@ -805,6 +797,7 @@ impl MainTui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Clear selection
|
// Clear selection
|
||||||
self.state.results_selected_indices.clear();
|
self.state.results_selected_indices.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user