Compare commits
No commits in common. "fff8235bc5ba217ed831a9f9d67a3f79e252d80c" and "0d984bfaa534cc7fb3e5f9480db1eb03175a3caa" have entirely different histories.
fff8235bc5
...
0d984bfaa5
5 changed files with 794 additions and 732 deletions
1472
Cargo.lock
generated
1472
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,9 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "jocalsend"
|
name = "jocalsend"
|
||||||
# 1.61803398874989484
|
# 1.61803398874989484
|
||||||
#------------^
|
#-----------^
|
||||||
version = "1.6.180339887"
|
version = "1.6.18033988"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
rust-version = "1.89"
|
||||||
authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
|
authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
|
||||||
keywords = ["p2p", "localsend", "tui", "linux"]
|
keywords = ["p2p", "localsend", "tui", "linux"]
|
||||||
description = "A TUI for LocalSend"
|
description = "A TUI for LocalSend"
|
||||||
|
|
|
||||||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
||||||
1.6180339887
|
1.618033988
|
||||||
|
|
|
||||||
|
|
@ -228,10 +228,13 @@ impl JocalService {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
#[derive(Default)]
|
|
||||||
pub enum RunningState {
|
pub enum RunningState {
|
||||||
#[default]
|
|
||||||
Running,
|
Running,
|
||||||
Stopping,
|
Stopping,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for RunningState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Running
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,4 @@
|
||||||
use std::{
|
use std::{collections::BTreeMap, net::SocketAddr, path::PathBuf, time::Duration};
|
||||||
collections::BTreeMap,
|
|
||||||
net::SocketAddr,
|
|
||||||
path::PathBuf,
|
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
Json,
|
Json,
|
||||||
|
|
@ -157,11 +152,10 @@ impl JocalService {
|
||||||
.map(|(_, peer)| peer.alias.as_str())
|
.map(|(_, peer)| peer.alias.as_str())
|
||||||
.unwrap_or("unknown peer")
|
.unwrap_or("unknown peer")
|
||||||
);
|
);
|
||||||
let num_bytes = bytes.len();
|
|
||||||
let resp = do_send_bytes(sessions, client, &session_id, content_id, token, bytes).await;
|
let resp = do_send_bytes(sessions, client, &session_id, content_id, token, bytes).await;
|
||||||
|
|
||||||
match resp {
|
match resp {
|
||||||
Ok(dur) => {
|
Ok(_) => {
|
||||||
send_tx(
|
send_tx(
|
||||||
JocalEvent::SendSuccess {
|
JocalEvent::SendSuccess {
|
||||||
content: content_id.to_owned(),
|
content: content_id.to_owned(),
|
||||||
|
|
@ -169,11 +163,6 @@ impl JocalService {
|
||||||
},
|
},
|
||||||
&tx,
|
&tx,
|
||||||
);
|
);
|
||||||
log::info!(
|
|
||||||
"transferred {num_bytes} bytes in {} seconds ({})",
|
|
||||||
dur.as_secs_f32(),
|
|
||||||
format_bytes_per_second(num_bytes as f32 / dur.as_secs_f32())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
send_tx(
|
send_tx(
|
||||||
|
|
@ -318,8 +307,6 @@ pub async fn handle_receive_upload(
|
||||||
// Create file path
|
// Create file path
|
||||||
let file_path = service.config.download_dir.join(&file_metadata.file_name);
|
let file_path = service.config.download_dir.join(&file_metadata.file_name);
|
||||||
|
|
||||||
let num_bytes = body.len();
|
|
||||||
|
|
||||||
// Write file
|
// Write file
|
||||||
if let Err(e) = tokio::fs::write(&file_path, body).await {
|
if let Err(e) = tokio::fs::write(&file_path, body).await {
|
||||||
log::warn!("could not save content to {file_path:?}, got {e}");
|
log::warn!("could not save content to {file_path:?}, got {e}");
|
||||||
|
|
@ -327,8 +314,8 @@ pub async fn handle_receive_upload(
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
"wrote {num_bytes} from {} to {file_path:?}",
|
"saved content from {} to {file_path:?}",
|
||||||
session.sender.alias
|
&session.sender.alias
|
||||||
);
|
);
|
||||||
if let Ok(id) = Julid::from_str(session_id) {
|
if let Ok(id) = Julid::from_str(session_id) {
|
||||||
service.send_event(JocalEvent::ReceivedInbound(id));
|
service.send_event(JocalEvent::ReceivedInbound(id));
|
||||||
|
|
@ -357,7 +344,7 @@ pub async fn handle_cancel(
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"{} cancelled the transfer of {}",
|
"{} cancelled the transfer of {}",
|
||||||
session.sender.alias,
|
&session.sender.alias,
|
||||||
session
|
session
|
||||||
.files
|
.files
|
||||||
.values()
|
.values()
|
||||||
|
|
@ -384,7 +371,7 @@ async fn do_send_bytes(
|
||||||
content_id: &str,
|
content_id: &str,
|
||||||
token: &str,
|
token: &str,
|
||||||
body: Bytes,
|
body: Bytes,
|
||||||
) -> Result<Duration> {
|
) -> Result<()> {
|
||||||
let session = sessions
|
let session = sessions
|
||||||
.read()
|
.read()
|
||||||
.await
|
.await
|
||||||
|
|
@ -407,15 +394,13 @@ async fn do_send_bytes(
|
||||||
.body(body);
|
.body(body);
|
||||||
|
|
||||||
debug!("Uploading bytes: {request:?}");
|
debug!("Uploading bytes: {request:?}");
|
||||||
let now = Instant::now();
|
|
||||||
let response = request.send().await?;
|
let response = request.send().await?;
|
||||||
let dur = Instant::now() - now;
|
|
||||||
|
|
||||||
if response.status() != 200 {
|
if response.status() != 200 {
|
||||||
log::warn!("non-200 remote response: {response:?}");
|
log::warn!("non-200 remote response: {response:?}");
|
||||||
Err(LocalSendError::UploadFailed)
|
Err(LocalSendError::UploadFailed)
|
||||||
} else {
|
} else {
|
||||||
Ok(dur)
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -479,14 +464,3 @@ async fn do_prepare_upload(
|
||||||
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_bytes_per_second(bps: f32) -> String {
|
|
||||||
if bps >= 1024.0f32.powi(2) {
|
|
||||||
return format!("{} MB/s", bps / 1024.0f32.powi(2));
|
|
||||||
}
|
|
||||||
if bps >= 1024.0 {
|
|
||||||
return format!("{} KB/s", bps / 1024.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
format!("{bps} B/s")
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue