Release 1.6180339887
- drop the rust version from the Cargo.toml - info-log the upload transfer rate
This commit is contained in:
parent
598c9109f8
commit
fff8235bc5
4 changed files with 35 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1344,7 +1344,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "jocalsend"
|
||||
version = "1.6.18033988"
|
||||
version = "1.6.180339887"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-server",
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
[package]
|
||||
name = "jocalsend"
|
||||
# 1.61803398874989484
|
||||
#-----------^
|
||||
version = "1.6.18033988"
|
||||
#------------^
|
||||
version = "1.6.180339887"
|
||||
edition = "2024"
|
||||
rust-version = "1.89"
|
||||
authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
|
||||
keywords = ["p2p", "localsend", "tui", "linux"]
|
||||
description = "A TUI for LocalSend"
|
||||
|
|
|
|||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
|||
1.618033988
|
||||
1.6180339887
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
use std::{collections::BTreeMap, net::SocketAddr, path::PathBuf, time::Duration};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
net::SocketAddr,
|
||||
path::PathBuf,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use axum::{
|
||||
Json,
|
||||
|
|
@ -152,10 +157,11 @@ impl JocalService {
|
|||
.map(|(_, peer)| peer.alias.as_str())
|
||||
.unwrap_or("unknown peer")
|
||||
);
|
||||
let num_bytes = bytes.len();
|
||||
let resp = do_send_bytes(sessions, client, &session_id, content_id, token, bytes).await;
|
||||
|
||||
match resp {
|
||||
Ok(_) => {
|
||||
Ok(dur) => {
|
||||
send_tx(
|
||||
JocalEvent::SendSuccess {
|
||||
content: content_id.to_owned(),
|
||||
|
|
@ -163,6 +169,11 @@ impl JocalService {
|
|||
},
|
||||
&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) => {
|
||||
send_tx(
|
||||
|
|
@ -307,6 +318,8 @@ pub async fn handle_receive_upload(
|
|||
// Create file path
|
||||
let file_path = service.config.download_dir.join(&file_metadata.file_name);
|
||||
|
||||
let num_bytes = body.len();
|
||||
|
||||
// Write file
|
||||
if let Err(e) = tokio::fs::write(&file_path, body).await {
|
||||
log::warn!("could not save content to {file_path:?}, got {e}");
|
||||
|
|
@ -314,7 +327,7 @@ pub async fn handle_receive_upload(
|
|||
}
|
||||
|
||||
log::info!(
|
||||
"saved content from {} to {file_path:?}",
|
||||
"wrote {num_bytes} from {} to {file_path:?}",
|
||||
session.sender.alias
|
||||
);
|
||||
if let Ok(id) = Julid::from_str(session_id) {
|
||||
|
|
@ -371,7 +384,7 @@ async fn do_send_bytes(
|
|||
content_id: &str,
|
||||
token: &str,
|
||||
body: Bytes,
|
||||
) -> Result<()> {
|
||||
) -> Result<Duration> {
|
||||
let session = sessions
|
||||
.read()
|
||||
.await
|
||||
|
|
@ -394,13 +407,15 @@ async fn do_send_bytes(
|
|||
.body(body);
|
||||
|
||||
debug!("Uploading bytes: {request:?}");
|
||||
let now = Instant::now();
|
||||
let response = request.send().await?;
|
||||
let dur = Instant::now() - now;
|
||||
|
||||
if response.status() != 200 {
|
||||
log::warn!("non-200 remote response: {response:?}");
|
||||
Err(LocalSendError::UploadFailed)
|
||||
} else {
|
||||
Ok(())
|
||||
Ok(dur)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -464,3 +479,14 @@ async fn do_prepare_upload(
|
|||
|
||||
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