diff --git a/Cargo.lock b/Cargo.lock index 305bc17..01cf656 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1337,7 +1337,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "to-streamshare" -version = "0.3.1" +version = "0.4.0" dependencies = [ "clap", "kdam", diff --git a/Cargo.toml b/Cargo.toml index 213be0a..fe418f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "to-streamshare" -version = "0.3.1" +version = "0.4.0" edition = "2021" description = "Upload to streamshare (to-ss > toss) from the terminal" license = "MIT" @@ -8,7 +8,7 @@ homepage = "https://waradu.dev" repository = "https://github.com/Waradu/to-streamshare" readme = "README.md" authors = ["Waradu"] -keywords = ["streamshare","file-sharing","upload"] +keywords = ["streamshare", "file-sharing", "upload"] [dependencies] clap = { version = "4.5.20", features = ["derive"] } @@ -18,4 +18,4 @@ tokio = { version = "1.40.0", features = ["full"] } [[bin]] name = "toss" -path = "src/main.rs" \ No newline at end of file +path = "src/main.rs" diff --git a/src/main.rs b/src/main.rs index 1685fac..08099e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::{io::Write, time::Instant}; + use clap::{CommandFactory, Parser}; use kdam::{tqdm, BarExt, Column, RichProgress, Spinner, term::Colorizer}; use streamshare::{delete, upload}; @@ -122,3 +124,19 @@ fn parse_delete_param(param: &str) -> Option<(&str, &str)> { None } } + +fn readable(bytes: u64) -> String { + const KB: f64 = 1024.0; + const MB: f64 = KB * 1024.0; + const GB: f64 = MB * 1024.0; + + if bytes as f64 >= GB { + format!("{:.2}gb", bytes as f64 / GB) + } else if bytes as f64 >= MB { + format!("{:.2}mb", bytes as f64 / MB) + } else if bytes as f64 >= KB { + format!("{:.2}kb", bytes as f64 / KB) + } else { + format!("{}b", bytes) + } +}