From 72957f779a62a85c9b6be5de9729fc9413c9619f Mon Sep 17 00:00:00 2001 From: Waradu Date: Sat, 19 Oct 2024 22:57:32 +0200 Subject: [PATCH] added --delete option to delete files --- Cargo.lock | 6 +++--- Cargo.toml | 4 ++-- README.md | 3 ++- src/main.rs | 34 +++++++++++++++++++++++++++++++--- test.txt | 2 +- 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 167d1f6..c21c290 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1191,9 +1191,9 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "streamshare" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef90535ebe65d462a94bb3c3ab55f0b1ac2f500124724948c28527c219069117" +checksum = "b858ea2a485166fdb9850afa3016d4bd1cd131fd13bab39b74c1e860cfd93a4b" dependencies = [ "futures", "reqwest", @@ -1306,7 +1306,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "to-streamshare" -version = "0.1.0" +version = "0.2.0" dependencies = [ "clap", "streamshare", diff --git a/Cargo.toml b/Cargo.toml index 2c96e37..c4d8f92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "to-streamshare" -version = "0.1.0" +version = "0.2.0" edition = "2021" description = "Upload to streamshare (to-ss > toss) from the terminal" license = "MIT" @@ -12,7 +12,7 @@ keywords = ["streamshare","file-sharing","upload"] [dependencies] clap = { version = "4.5.20", features = ["derive"] } -streamshare = "1.0.0" +streamshare = "1.1.0" tokio = { version = "1.40.0", features = ["full"] } [[bin]] diff --git a/README.md b/README.md index 2f24d07..d2050af 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,5 @@ 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` \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 65df049..82bd6df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,15 +5,32 @@ use streamshare::upload; #[command(version, about, long_about = None)] 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, } #[tokio::main] async fn main() { let args = Args::parse(); - if let Some(file_path) = args.file { + if let Some(delete_param) = args.delete { + if let Some((identifier, deltoken)) = parse_delete_param(&delete_param) { + match streamshare::delete(identifier, deltoken).await { + Ok(_) => println!("File deleted successfully"), + Err(e) => eprintln!("Error deleting file: {}", e), + } + } else { + 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).await { - Ok((file_identifier, _deletion_token)) => { + Ok((file_identifier, deletion_token)) => { let download_url = format!( "https://streamshare.wireway.ch/download/{}", file_identifier @@ -21,10 +38,21 @@ async fn main() { println!("File uploaded successfully"); println!("Download URL: {}", download_url); + println!("File Identifier: {}", file_identifier); + println!("Deletion Token: {}", deletion_token); } Err(e) => eprintln!("Error: {}", e), } } else { - eprintln!("Please provide a file path"); + eprintln!("Please provide a file path or use --delete"); + } +} + +fn parse_delete_param(param: &str) -> Option<(&str, &str)> { + let parts: Vec<&str> = param.splitn(2, '/').collect(); + if parts.len() == 2 { + Some((parts[0], parts[1])) + } else { + None } } diff --git a/test.txt b/test.txt index b6fc4c6..c7a5547 100644 --- a/test.txt +++ b/test.txt @@ -1 +1 @@ -hello \ No newline at end of file +Thanks to wireway.ch! \ No newline at end of file