mirror of
https://github.com/Waradu/to-streamshare.git
synced 2025-04-21 20:04:06 +02:00
updated to streamshare v3
This commit is contained in:
parent
67c91ccad7
commit
c7e859badf
4 changed files with 54 additions and 8 deletions
47
src/main.rs
47
src/main.rs
|
@ -1,3 +1,5 @@
|
|||
use std::{io::Write, time::Instant};
|
||||
|
||||
use clap::{CommandFactory, Parser};
|
||||
use streamshare::{delete, upload};
|
||||
|
||||
|
@ -29,13 +31,40 @@ async fn main() {
|
|||
eprintln!("Invalid format for --delete. Use 'file_identifier/deletion_token' (e.g., 'abc123/def456')");
|
||||
}
|
||||
} else if let Some(file_path) = args.file {
|
||||
match upload(&file_path, true).await {
|
||||
let start_time = Instant::now();
|
||||
let mut file_size: u64 = 0;
|
||||
|
||||
let show_progress = |uploaded_bytes, total_bytes| {
|
||||
let percentage = (uploaded_bytes as f64 / total_bytes as f64) * 100.0;
|
||||
let uploaded = readable(uploaded_bytes);
|
||||
let total = readable(total_bytes);
|
||||
let elapsed_secs = start_time.elapsed().as_secs_f64();
|
||||
let speed = readable((uploaded_bytes as f64 / elapsed_secs) as u64);
|
||||
file_size = total_bytes;
|
||||
|
||||
print!(
|
||||
"\r\x1b[2K{:.2}% {}/{} ({}/s)",
|
||||
percentage, uploaded, total, speed
|
||||
);
|
||||
std::io::stdout().flush().unwrap();
|
||||
};
|
||||
|
||||
match upload(&file_path, show_progress).await {
|
||||
Ok((file_identifier, deletion_token)) => {
|
||||
let download_url = format!(
|
||||
"https://streamshare.wireway.ch/download/{}",
|
||||
file_identifier
|
||||
);
|
||||
|
||||
let elapsed_secs = start_time.elapsed().as_secs_f64();
|
||||
println!(
|
||||
"\r\x1b[2K100.00% {}/{} (Upload completed in {:.2}s)",
|
||||
readable(file_size),
|
||||
readable(file_size),
|
||||
elapsed_secs
|
||||
);
|
||||
println!();
|
||||
|
||||
println!("File uploaded successfully");
|
||||
println!("Download URL: {}", download_url);
|
||||
println!("File Identifier: {}", file_identifier);
|
||||
|
@ -56,3 +85,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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue