mirror of
https://github.com/Waradu/to-streamshare.git
synced 2025-04-22 04:14: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
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -1191,9 +1191,9 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "streamshare"
|
name = "streamshare"
|
||||||
version = "2.0.0"
|
version = "3.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "723b8059b8580d19ea0bdd3202fc8ba38c01719ee5ad2d5b70e530e8f3c5e22e"
|
checksum = "d8a66009b98588531c068a6b1fc2345a05292dd279c73554d514fd47f926b2e7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
@ -1306,7 +1306,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "to-streamshare"
|
name = "to-streamshare"
|
||||||
version = "0.3.1"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"streamshare",
|
"streamshare",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "to-streamshare"
|
name = "to-streamshare"
|
||||||
version = "0.3.1"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Upload to streamshare (to-ss > toss) from the terminal"
|
description = "Upload to streamshare (to-ss > toss) from the terminal"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -8,13 +8,13 @@ homepage = "https://waradu.dev"
|
||||||
repository = "https://github.com/Waradu/to-streamshare"
|
repository = "https://github.com/Waradu/to-streamshare"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Waradu"]
|
authors = ["Waradu"]
|
||||||
keywords = ["streamshare","file-sharing","upload"]
|
keywords = ["streamshare", "file-sharing", "upload"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.20", features = ["derive"] }
|
clap = { version = "4.5.20", features = ["derive"] }
|
||||||
streamshare = "2"
|
streamshare = "3"
|
||||||
tokio = { version = "1.40.0", features = ["full"] }
|
tokio = { version = "1.40.0", features = ["full"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "toss"
|
name = "toss"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
Upload files to [streamshare](https://streamshare.wireway.ch) with the terminal.
|
Upload files to [streamshare](https://streamshare.wireway.ch) with the terminal.
|
||||||
|
|
||||||
Run `cargo install to-streamshare` to install it and use it with `toss "filepath"`.
|
Run `cargo install to-streamshare` to install it and use it with `toss "filepath"`.
|
||||||
|
|
||||||
Delete a file with `toss --delete file_identifier/deletion_token`
|
Delete a file with `toss --delete file_identifier/deletion_token`
|
||||||
|
|
47
src/main.rs
47
src/main.rs
|
@ -1,3 +1,5 @@
|
||||||
|
use std::{io::Write, time::Instant};
|
||||||
|
|
||||||
use clap::{CommandFactory, Parser};
|
use clap::{CommandFactory, Parser};
|
||||||
use streamshare::{delete, upload};
|
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')");
|
eprintln!("Invalid format for --delete. Use 'file_identifier/deletion_token' (e.g., 'abc123/def456')");
|
||||||
}
|
}
|
||||||
} else if let Some(file_path) = args.file {
|
} 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)) => {
|
Ok((file_identifier, deletion_token)) => {
|
||||||
let download_url = format!(
|
let download_url = format!(
|
||||||
"https://streamshare.wireway.ch/download/{}",
|
"https://streamshare.wireway.ch/download/{}",
|
||||||
file_identifier
|
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!("File uploaded successfully");
|
||||||
println!("Download URL: {}", download_url);
|
println!("Download URL: {}", download_url);
|
||||||
println!("File Identifier: {}", file_identifier);
|
println!("File Identifier: {}", file_identifier);
|
||||||
|
@ -56,3 +85,19 @@ fn parse_delete_param(param: &str) -> Option<(&str, &str)> {
|
||||||
None
|
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