From a452ff16319ac9ae8fc1f7f63dbae16b7178efd5 Mon Sep 17 00:00:00 2001 From: Waradu Date: Sun, 20 Oct 2024 20:51:51 +0200 Subject: [PATCH] added download --- Cargo.lock | 6 +++--- Cargo.toml | 6 +++--- README.md | 13 ++++++++++--- src/main.rs | 44 ++++++++++++++++++++++++++++++++++---------- 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b33a924..94a33a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1237,9 +1237,9 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "streamshare" -version = "4.0.0" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8642382451166982e9ca79fa523c65350c72b113b5c4a89887a1181a16ac44" +checksum = "b1960eb9ada032cacbd7b75b1255468a007459729009b76e508579bd49d97171" dependencies = [ "futures", "reqwest", @@ -1362,7 +1362,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "to-streamshare" -version = "0.5.0" +version = "0.6.0" dependencies = [ "clap", "console", diff --git a/Cargo.toml b/Cargo.toml index b86b3a7..391189d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "to-streamshare" -version = "0.5.0" +version = "0.6.0" edition = "2021" description = "Upload to streamshare (to-ss > toss) from the terminal" license = "MIT" @@ -14,9 +14,9 @@ keywords = ["streamshare", "file-sharing", "upload"] clap = { version = "4.5.20", features = ["derive"] } console = "0.15.8" kdam = { version = "0.5.2", features = ["rich", "spinner"] } -streamshare = "4" +streamshare = "4.1" tokio = { version = "1.40.0", features = ["full"] } [[bin]] name = "toss" -path = "src/main.rs" +path = "src/main.rs" \ No newline at end of file diff --git a/README.md b/README.md index 0958862..731465f 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,19 @@ cargo install to-streamshare ```bash toss "filepath" -toss "filepath" --chunk-size 100 # set chunk_size to 100 -toss "filepath" --server "streamshare.myserver.com" # set server to your server +toss --chunk-size 100 "filepath" # set chunk_size to 100 +toss --server "streamshare.myserver.com" "filepath" # set server to your server ``` ### Delete ```bash -toss --delete file_identifier/deletion_token +toss --delete "file_identifier/deletion_token" ``` + +### Download + +```bash +toss --download "file_identifier" +toss --download "file_identifier" --path "" # uses current path as default +``` \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 37da42d..0de59a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,19 +13,11 @@ use streamshare::StreamShare; struct Args { file: Option, - #[arg( - short, - long, - value_name = "DELETE", - help = "Specify a file to delete in the format 'file_identifier/deletion_token' (e.g., 'abc123/def456')" - )] - delete: Option, - #[arg( short, long, value_name = "SERVER", - help = "Specify a server", + help = "Specify a server.", default_value = "streamshare.wireway.ch" )] server: Option, @@ -33,11 +25,33 @@ struct Args { #[arg( short, long, - value_name = "CHUNK-SIZE", + value_name = "CHUNK_SIZE", help = "Specify a chunk size", default_value = "1048576" )] chunk_size: Option, + + #[arg( + long, + value_name = "DELETE", + help = "Delete a file. Format: 'file_identifier/deletion_token'" + )] + delete: Option, + + #[arg( + long, + value_name = "DOWNLOAD", + help = "Download a file. Format: 'file_identifier'" + )] + download: Option, + + #[arg( + short, + long, + value_name = "PATH", + help = "Set the path to download the file to." + )] + path: Option, } #[tokio::main] @@ -63,6 +77,16 @@ async fn main() -> std::io::Result<()> { } else { eprintln!("Invalid format for --delete. Use 'file_identifier/deletion_token' (e.g., 'abc123/def456')"); } + } else if let Some(download) = args.download { + let path = match args.path { + Some(p) => p, + None => "".to_string() + }; + + match client.download(download.as_str(), path.as_str()).await { + Ok(_) => println!("File downloaded successfully"), + Err(e) => eprintln!("Error downloaded file: {}", e), + } } else if let Some(file_path) = args.file { kdam::term::init(stderr().is_terminal()); kdam::term::hide_cursor()?;